Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App Crashed when device time is in 24 hour format

In my App if IPhone device time is in 12 hour formate then date formatter works correctly but if device time is in 24 hour formate then app crashed.

 let dateFormatter = NSDateFormatter();
 dateFormatter.dateStyle = NSDateFormatterStyle.ShortStyle
 dateFormatter.timeStyle = NSDateFormatterStyle.NoStyle;
 dateFormatter.dateFormat = "hh:mm a";
 var dt1 = dateFormatter.dateFromString(arrSecond.objectAtIndex(n) as! String)
like image 669
Nandini Prashant Barve Avatar asked Oct 15 '16 06:10

Nandini Prashant Barve


1 Answers

@Rajan Thanks for giving me idea of NSLocale. I set the dateformatter's locale identifier to "en_US_POSIX". i just add this below line in my code after allocating date formatter. dateformatter.locale = NSLocale(localeIdentifier:"en_US_POSIX") Thanks frnd for giving this idea

like image 140
Nandini Prashant Barve Avatar answered Oct 09 '22 19:10

Nandini Prashant Barve