NSDate * now = [NSDate date];
I get this date one hour earlier. Probably it’s because it use UTC.
How can I get system current date?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
[NSDate date]returns the current date. However, anNSDatedoes not have a timezone of its own, it’s just an absolute point in time. The timezone only comes into play when you present the date as a string or convert it into date components (like day, month, hour, etc.).Use
NSDateFormatterto get a string representation of the date in the current time zone or usesetTimeZone:on the date formatter to specify a different one. If you simply useNSLog, the date will be presented in the UTC timezone (by implicitly callingdescriptionon the date object).Use the
NSCalendarmethodcomponents:fromDate:to extract individual components (with a given timezone) from your date for typical comparisons, like “do these two dates fall on the same day in this timezone?”.