Ios has eight hours of printing time difference

Source: Internet
Author: User
Tags cst time

This problem has actually been encountered several times, and many things have not been carefully studied. The solution is also very violent and directly added for 8 hours.

After debugging, I found that this is not the case.

NSDate * nowDate = [NSDate date]; // The time here is CST time. The variable value is correct in the variable View window.
However, if you print it out using NSLog (@ "nowDate: % @", nowDate), you will find that eight hours are missing;

I tried to use DateFormater to convert time to string and string to time, and view the value of the time variable. That is to say, only NSLog (@ "nowDate: % @", nowDate) when the time object is printed directly, the display time is 8 hours less.

The format of time in NSLog is converted by GMT time. In this way, the conversion will be less than 8 hours, and the solution is also very simple. Just do not print it like this, how to Use the Internal Computing in the code, but when it comes to operations that need to be displayed on the interface or that need to be assigned with a print value, use DateFormater to format it as the required string, and then you can use it with confidence.

Related Article

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.