Time Zone conversion form stringdate
Posted
by Kishore
on Stack Overflow
See other posts from Stack Overflow
or by Kishore
Published on 2010-05-17T06:43:11Z
Indexed on
2010/05/17
6:50 UTC
Read the original article
Hit count: 160
cocoa
Hi,
I have a stringdate 16-MAY-2010 23:04:44 which i need to convert to gmt time zone that is the out put required is 17-May-2010 12:03:03.
I used date formatters to convert but the result i am getting is not in the format i required.I am sending the code please let me know if i am doing correct or not
Here is the code:
NSString *timeStamp = [format stringFromDate:[NSDate date]]; NSString *output = [timeConv dateStringFromString:timeStamp];
(NSString *)dateStringFromString:(NSString *)sourceString {
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; [dateFormatter setDateFormat:@"dd-MMMM-yyyy HH:MM:ss"]; NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; [dateFormatter setTimeZone:gmt]; NSDate *date = [dateFormatter dateFromString:sourceString]; return [dateFormatter stringFromDate:date];
}
The out put i am getting is the same old time without conversion. so please let me know the correct solution.
© Stack Overflow or respective owner