Ios timestamp current time mutual conversion

Source: Internet
Author: User

1. today, when I made a webservice interface, I was asked to pass a timestamp, and then I started searching for it on Google. two problems are encountered: 1. The current time is converted to the timestamp. 2. The difference between the obtained current time and the system time is 8 hours. 1, the conversion method is NSString * timeSp = [NSString stringWithFormat: @ "% d", (long) [localeDate timeIntervalSince1970]; NSLog (@ "timeSp: % @", timeSp ); // The timestamp value 2 converts the obtained time to the current time NSDate * datenow = [NSDate date]; // the current time, the output shows the format NSTimeZone * zone = [NSTimeZone systemTimeZone]; NSInteger interval = [zone secondsFromGMTForDate: datenow]; NSDate * localeDate = [datenow dateByAddingTimeInterval: interval]; NSLog (@ "% @", localeDate); 3. NSDate * confromTimesp = [NSDate dateWithTimeIntervalSince1970: 1363948516]; NSLog (@ "1363948516 = % @", confromTimesp); 4. complete

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.