ios - Wrong date and time in NSDateDormatter -
i want create nsdate 2 nsstrings represent time , date.
look @ code:
nsdateformatter *form = [[nsdateformatter alloc] init]; [form setdateformat:@"hh:mm dd.mm.yyyy"]; nsdate *notdate = [form datefromstring:[@"" stringbyappendingformat:@"%@ %@",z.time,z.date]]; nslog(@"%@ // %@",[@"" stringbyappendingformat:@"%@ %@",z.time,z.date],notdate); log show me numbers:
12:00 12.05.2013 // 2013-05-11 18:00:00 +0000 on left side - 2 strings, on right - date
first got 12:00, when second 18:00! besides, got different days!
why different?
if change
[form setdateformat:@"hh:mm dd.mm.yyyy"]; to
[form setdateformat:@"hh:mm dd.mm.yyyy"]; it use 24 hour format.
nslog(@"%@ // %@",[@"" stringbyappendingformat:@"%@ %@",z.time,z.date],notdate); should output 00:00 12.05.2013 // 2013-05-11 18:00:00 +0000 , explains everything:
the nsdateformatter takes current locale in account if dont manually change it, while internally every nsdate object saved in gmt (hence +0000).
according profile located in perm — 6 hours ahead of gmt.
so dates same, once printed timezone in account, once without.
Comments
Post a Comment