NSDate returns the current date. Though it can convert to and from string format in different locales/time zones, NSDate has no internal concept of a time zone. NSDates are not bound to any particular region. If you and anyone else in the world asked your devices to [NSDate date] simultaneously, you'd get equal results — not because it always returns in GMT but because it doesn't return in a time zone-specific manner. In Cocoa, a date is a specific moment in the history of the Earth. How you write a date is related to your calendar, your time zone and your locale.
You aren't getting tomorrow's date, you're getting the correct date and then noticing it gives a different day if expressed in GMT. It's the correct date, just written differently from what you'd like.
'description' is a method overridden from NSObject. When you NSLog an object, what happens internally is that the description method is called and the string returned is printed. So you should get identical results from logging object
and [object description]
, since the former calls description and prints that string, the latter calls description then calls description on the resulting string and prints that. NSStrings return themselves as the result of description.
It should be the default behaviour but to get a meaningful description, try:
NSLog(@"%@", [[NSDate date] descriptionWithCalendarFormat:nil
timeZone:[NSTimeZone localTimeZone] locale:[NSLocale currentLocale]]);
If that still logs in GMT then your device believes itself to be in GMT. I've no idea how reliable the simulator is about that sort of thing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…