2012-05-10 52 views
0

我试图格式化由阵列给出的NSString包括在这个格式的日期:发行与日期格式

DD/MM/YYYY

和我试图把它与这个码格式:

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]; 

如果不好的日期值,例如,是11/05/2012,fechaDescuento格式化:

2012-05-10 22:00:00 +0000

总是在前一天以另一种格式。

请问,你能帮我吗?

感谢

+0

你在哪个时区?我猜你有一个从伦敦抵消的-2小时。 – sblom

+0

另外,日期本身没有以任何方式格式化,这只是它的默认描述字符串。要以您选择的格式输出日期,请再次使用日期格式化程序。 – fzwo

回答

1

我想如果您在dateFromString:呼叫前加[dateformatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];,我认为它会告诉你接近你所期望的。

+0

非常感谢!!!! – theomen