NSDateFormatter - 1 day incorrect?

主宰稳场 提交于 2020-01-30 05:08:12

问题


I am importing a CSV file with a date format of month/day/year (e.g. 21/01/2007).

I am looping through the CSV some are working but some are coming out with the date 1 day previous with a time of 23:00? One of the dates that are not working would look like this:

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"M/d/yyyy"];
    NSDate *date = [dateFormatter dateFromString:@"10/7/2007"];

but when I output the date in an NSLog it has this:

    NSLog(@"Date: String: %@ Date: %@", @"10/7/2007", date);

Date: String: 10/7/2007 Date: 2007-10-06 23:00:00 GMT

What am I doing wrong?


回答1:


Sounds like you have a timezone problem, have you set the timezone?



来源:https://stackoverflow.com/questions/3854385/nsdateformatter-1-day-incorrect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!