Getting the date for the users current time zone?
When using NSDate to get today's date, I seem to be getting a date that is ahead in time. For example, today is February 1开发者_如何转开发9 but NSDate is giving me February 20?
What can I do to get the proper date?
I'm using
NSDate *today = [NSDate date];
to get todays date but the problem is that it's not in my current time zone.
This sentence doesn't make sense. An NSDate
object represents a single point in time, regardless of time zone. NSDate does not even have a sense of time zones.
To output a date as a string, always create an instance of NSDateFormatter
and call its stringFromDate:
method. By default, NSDateFormatter
uses the current user's time zone.
精彩评论