I am facing a a strange issue in date. i am getting varied results on the time format. My code is
formatter=[[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy/MM/dd hh:mma"];
NSDate *currentdate=[formatter dateFromString:[formatter stringFromDate:[NSDate date]]];
NSLog(@"Current Date %@",currentdate);
My output in simulator and other device are
Current Date 2013-11-13 11:55:00 +0000
But in one particular device(Iphone 5):the ouput i am recieving is
Current Date 2013-11-13 11:57:00 am +0000
Please help me to solve this issue.Thanks
If it is displaying a different hour you may need to set the default timezone after setting the dateFormat (this happens only after ios7)
[dateFormat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
it seems that the default timezone is the one the device has, so if you no specify the default timezone you might get strange results. Prior to ios7 it was always GMT.
update:
if the NSDate is nil after the formatting you should probably use:
[dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
I had this issue with a Mexican iPhone, if you like your users to be happy with your app I strongly recommend always adding this code. I always use both code sniplets since IOS7
You need to check your "Date time format" set in iPhone Default Setting (Setting -> General -> Date and Time).
if in this setting time format is set as 24 hr then u will get time in 24 hr format.
If it is set as 12 hr format then u will get 12 hr date time format.
I think in ur iPhone5 device date time setting is set as 12 Hr format
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With