nsdate - Converting ISO8601 Date Format to local time (iOS) -
so there section on web application users can enter events , web service sends events mobile app in following format:
"yyyy-mm-dd't'hh:mm:sszzzzz"
i'm having issues trying convert string date can time event (formatted in correct timezone well), example here's 1 comes on "2015-03-20t20:00:00-07:00", when pull time should 1pm pacific time. instead either 8pm or 3am (depending on whether add utc abbreviation date formatter).
here's have far, know i'm missing here & maybe there's date formatter needs used far can't figure out i'm going wrong.
nsstring *datepattern = @"yyyy-mm-dd't'hh:mm:sszzzzz"; nsdateformatter *dateformatter = [nsdateformatter new]; [dateformatter setdateformat:datepattern]; nsstring *sstring = [valuedict valueforkey:@"start_date"]; nsdate *startdate = [dateformatter datefromstring:sstring]; nsdateformatter *timeformatter = [nsdateformatter new]; [timeformatter setdateformat:@"hh:mm a"]; [timeformatter setlocale:[nslocale systemlocale]]; nsstring *timestring = [timeformatter stringfromdate:startdate];
2015-03-20t20:00:00-07:00
is 8pm pacific daylight time.
if you're representing 1pm pdt, that's either
2015-03-20t13:00:00-07:00
or represent in "zulu" (i.e. gmt/utc)
2015-03-20t20:00:00z
when working web service, latter common convention iso 8601 dates. then, when present user, present them in local timezone (using nsdateformatter
default timezone
setting.
note, when using nsdateformatter
prepare iso 8601 dates, want ensure specify locale
of en_us_posix
outlined in technical q&a qa1480. when designing app audience isn't critical, it's best practice in case user not using gregorian calendar on device.
Comments
Post a Comment