Date & time which has a format "yyyyMMddHHmmss". I am unable to convert this Time into EST time zone.I follows some tutorial but i didn't get proper result.If there is any API for this conversion please let me know.
Asked
Active
Viewed 648 times
-1
-
possible duplicate of [Convert any timezone date in system timezone in iOS](http://stackoverflow.com/questions/15475348/convert-any-timezone-date-in-system-timezone-in-ios) – Brandon May 08 '14 at 07:00
3 Answers
2
You should do it the following way:
1) First, create an NSDateFormatter to get the NSDate
NSDateFormatter *serverFormatter = [[NSDateFormatter alloc] init];
[serverFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
[serverFormatter setDateFormat:@"'at 'HH:mm' of 'dd/MM/yyyy"];
2) Convert the string (consider it is defined as theString) to a NSDate:
NSDate *theDate = [serverFormatter dateFromString:theString];
3) Create an NSDateFormatter to convert theDate to the user:
NSDateFormatter *userFormatter = [[NSDateFormatter alloc] init];
[userFormatter setDateFormat:@"HH:mm dd/MM/yyyy"];
[userFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"EST"]];
3) Get the string from the userFormatter:
NSString *dateConverted = [userFormatter stringFromDate:theDate];
hope this helps you !!!

Arpit Kulsreshtha
- 2,452
- 2
- 26
- 52
1
NSString *startTime = @"20140508063630";
NSDateFormatter *workingHoursFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"EST"];
[workingHoursFormatter setTimeZone:timeZone];
[workingHoursFormatter setDateFormat:@"yyyyMMddHHmmss"];
NSDate *openingTime = [workingHoursFormatter dateFromString:startTime];
Try that. Works here.

Ruby
- 528
- 3
- 14
1
NSDateFormatter *inputDateFormat = [[NSDateFormatter alloc] init];
[inputDateFormat setDateFormat:@"yyyyMMddHHmmss"];
[inputDateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSDateFormatter *outputDateFormat = [[NSDateFormatter alloc] init];
[outputDateFormat setDateFormat:@"yyyyMMddHHmmss"];
[inputDateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"EST"]];
NSString *outputDate = [outputDateFormat stringFromDate:[inputDateFormat dateFromString:@"20140508063630"]];
NSLog(@"%@",outputDate);

sargeras
- 179
- 1
- 14