ios - How does NSDate seem to know it's TimeZone? -


i'm confused how these 2 nsdate objects seem know timezone in. under impression nsdate object stored point in time , no information timezone.

i'm creating , logging 2 dates this:

nsstring* timestring = @"6:04 pm";  nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; [dateformatter setlocale:[nslocale localewithlocaleidentifier:@"en_us_posix"]]; [dateformatter setdateformat:@"h:mm a"]; nsdate *time = [dateformatter datefromstring:timestring];  nsdateformatter *currentformatter = [[nsdateformatter alloc] init]; [currentformatter settimestyle:nsdateformatterlongstyle]; nslog(@"%@", [currentformatter stringfromdate:time]); nslog(@"%@", [currentformatter stringfromdate:[nsdate date]]); 

this produces output:

18:04:00 gmt 11:12:36 bst 

how know first date gmt , second bst?

(it's british summer time here. mileage may vary in respect)

you're right, nsdate doesn't have time zone. results don't contradict that, because you're not printing dates-- you're printing subset of date information produced passing them through date formatter. currentformatter returns time of day information, not date information. if add line:

[currentformatter setdatestyle:nsdateformatterlongstyle]; 

then results like:

january 1, 2000 @ 6:04:00 pm mst september 30, 2015 @ 11:14:39 mdt 

in other words, show different time zones because they're on different dates, , time zone reflects what's in effect on date. in case it's mdt on jan 1 2000 have been mst.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -