i wrote function that converting current time utc-gmt or gmt -utc. The functions just works fine if msgArrivedDate is null. If it's not ( that means , msgArrivedDate comes from rest service that doses not convert .
jSON parse part :
NSArray *messageSentTime = [[args valueForKey:@"messageSendDate"] objectAtIndex:0];
for(int i=0 ;i< [messageSentTime count]; i++)
{
//[self timeZoneFormatter:@"GMT" :[messageSentTime objectAtIndex:i]];
NSLog(@"Converted time = %@",[self timeZoneFormatter:@"GMT" :[messageSentTime objectAtIndex:i]]);
Function part :
-(id)timeZoneFormatter:(NSString *)formatType : (NSString *)msgArrivedDate
{
NSDate *date;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
if([msgArrivedDate length] > 0)
{
date = [dateFormatter dateFromString:msgArrivedDate];
} else {
date = [NSDate date];
}
if([formatType isEqualToString:@"UTC"])
{
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
}
if([formatType isEqualToString:@"GMT"])
{
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
}
NSString *dateString = [dateFormatter stringFromDate:date];
return dateString;
}
ReST returned me to these values in UTC format :
"2013-09-24 15:03:17", "2013-09-25 12:09:22", "2013-09-25 13:07:45", "2013-09-25 13:08:19", "2013-09-25 14:22:38"
When i call the function, (NSLog(@"Converted time = %@",[self timeZoneFormatter:@"GMT" :[messageSentTime objectAtIndex:i]]))
returns :
messageSentTime = (
"2013-09-24 15:03:17",
"2013-09-25 12:09:22",
"2013-09-25 13:07:45",
"2013-09-25 13:08:19",
"2013-09-25 14:22:38" )
I think i am just missing little issue over here :( couldn't find yet ...