am/pm time to 24 hour format

Just convert it to a date using NSDateFormatter and the “h:mm a” format and convert it back to a string using the “HH:mm” format. Check out this date formatting guide to familiarize yourself with this material. let dateAsString = “6:35 PM” let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = “h:mm a” dateFormatter.locale = Locale(identifier: “en_US_POSIX”) // fixes … Read more

Convert ISO 8601 to NSDate

This works for me: NSString *dateString = @”2013-04-18T08:49:58.157+0000″; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@”yyyy-MM-dd’T’HH:mm:ss.SSSZ”]; // Always use this locale when parsing fixed format date strings NSLocale *posix = [[NSLocale alloc] initWithLocaleIdentifier:@”en_US_POSIX”]; [formatter setLocale:posix]; NSDate *date = [formatter dateFromString:dateString]; NSLog(@”date = %@”, date);

iPhone NSDateFormatter Timezone Conversion

To process the time zone with the colon in it, you just need to use 5 ‘Z’s. This is a pretty common date format, the ISO-8601 format. This will only work on iOS 6.x+ -(NSDate *) dateFromString:(NSString *)string { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@”yyyy-MM-dd’T’HH:mm:ssZZZZZ”]; return [formatter dateFromString:string]; }

Get current iPhone device timezone date and time from UTC-5 timezone date and time iPhone app?

I have tested your scenario and added some code for your reference. Please test the below and please let me know it is useful for you. NSString *dateStr = @”2012-07-16 07:33:01″; NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init]; [dateFormatter1 setDateFormat:@”yyyy-MM-dd HH:mm:ss”]; NSDate *date = [dateFormatter1 dateFromString:dateStr]; NSLog(@”date : %@”,date); NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone]; NSTimeZone *utcTimeZone … Read more

How can I convert including timezone date in swift?

Xcode 8 • Swift 3 You need to escape ‘T’ and use the appropriate timezone symbol. Note that it will depend if your date string represents a UTC (zero seconds from GMT) time timezone with Z “XXXXX” or without it +00:00 “xxxxx”: let dateString = “2015-08-14T20:02:25-04:00” let formatter = DateFormatter() formatter.locale = Locale(identifier: “en_US_POSIX”) formatter.dateFormat … Read more