Date format issue in ios7

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

Answers


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


Need Your Help

Is it possible to place “hints” in Windows Phone 7 TextBoxes?

c# silverlight visual-studio-2010 xaml windows-phone-7

I just got started programming for Windows Phone 7 after programming on Android for about half a year now. In Android, when I wanted textual input from a user, I would put a "hint" in the text box ...

Tokenize big files to hashtable in Java

java hashmap corpus

I'm having this problem: I'm reading 900 files and, after processing the files, my final output will be an HashMap<String, <HashMap<String, Double>>. First string is fileName, second