Pregunta

    NSString * dateString = [NSString stringWithFormat: @"%@",item.date];

    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
    NSDate* myDate = [dateFormatter dateFromString:dateString];

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"dd / M / Y 'ás' HH:mm ZZZZ"];
    NSString *stringFromDate = [formatter stringFromDate:myDate];

The data comes in like.... 2014-08-15T08:30:00-04:00

I want this date to be .... 15 - 08 - 2014 12:00

I want the date to be displayed in GMT format, or at least to show the right local time that the event starts, wether you live in US or Japan, and to not display the GMT timezone.

I've tried Z ZZ ZZZ ZZZZ ZZZZZ z zz zzz zzzz

nothing... can anyone help?

¿Fue útil?

Solución

try this code

NSString * dateString = @"2014-08-15T08:30:00-04:00";

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
NSDate* myDate = [dateFormatter dateFromString:dateString];

//[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setDateFormat:@"dd-MM-yyyy HH:mm:ss"];

NSLog(@"date--%@", [dateFormatter stringFromDate:myDate]);

output--`date--15-08-2014 18:00:00`
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top