iphone - Does [NSDate date] return the local date and time? -
am stupid? time thought [nsdate date] returned local date , time. after having trouble nsstringformatter/stringfromdate/datefromstring today noticed [nsdate date] returning 2011-03-06 11:00:00 +0000. after researching see [nsdate date] returns raw date gmt.
what purpose gmt offset portion serve if shows +0000? not understand [mydate description]. docs says supposed display gmt offset dst information. same thing [nsdate date].
bottom line me, if use [nsdate date] current date , after 2pm tomorrow's date in -10 time zone. not mention problems ran today nsdateformatter.
am seeing correctly? funny thing seem remember seeing [nsdate date] returning 2011-03-06 11:00:00 -36000, or did think seeing 2011-03-06 11:00:00 -10000.
i can work it, maybe can expound on me better understand nsdate.
nsdate returns current date. though can convert , string format in different locales/time zones, nsdate has no internal concept of time zone. nsdates not bound particular region. if , else in world asked devices [nsdate date] simultaneously, you'd equal results — not because returns in gmt because doesn't return in time zone-specific manner. in cocoa, date specific moment in history of earth. how write date related calendar, time zone , locale.
you aren't getting tomorrow's date, you're getting correct date , noticing gives different day if expressed in gmt. it's correct date, written differently you'd like.
'description' method overridden nsobject. when nslog object, happens internally description method called , string returned printed. should identical results logging object
, [object description]
, since former calls description , prints string, latter calls description calls description on resulting string , prints that. nsstrings return result of description.
it should default behaviour meaningful description, try:
nslog(@"%@", [[nsdate date] descriptionwithcalendarformat:nil timezone:[nstimezone localtimezone] locale:[nslocale currentlocale]]);
if still logs in gmt device believes in gmt. i've no idea how reliable simulator sort of thing.
Comments
Post a Comment