NSDateFormatter - 1 天不正确?
我正在导入日期格式为月/日/年的 CSV 文件(例如 21/01/2007)。
我正在循环遍历 CSV,有些正在工作,但有些输出的日期是 1 天前的 23:00?不起作用的日期之一如下所示:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"M/d/yyyy"];
NSDate *date = [dateFormatter dateFromString:@"10/7/2007"];
但是当我在 NSLog 中输出日期时,它具有以下内容:
NSLog(@"Date: String: %@ Date: %@", @"10/7/2007", date);
Date: String: 10/7/2007 Date: 2007-10-06 23:00:00 GMT
What am我做错了吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来你有时区问题,你设置时区了吗?
Sounds like you have a timezone problem, have you set the timezone?