i’m trying to format a NSString given by array that includes a date in this format:
dd/MM/yyyy
and I’m trying to format it with this code:
NSDate *fechaDescuento = [[NSDate alloc] init];
NSDateFormatter *dateformater = [[NSDateFormatter alloc] init];
NSString *baddate = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@", descuento.fechaDescuento]];
[dateformater setDateFormat:@"dd/MM/yyyy"];
[dateformater setLocale:[NSLocale currentLocale]];
fechaDescuento = [dateformater dateFromString:baddate];
If bad date value, for instance, is 11/05/2012, fechaDescuento is formatted:
2012-05-10 22:00:00 +0000
Always one day before and with another format.
Please, can you help me with that?
Thanks
I think if you add
[dateformatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];before yourdateFromString:call, I think it’ll show you closer to what you expect.