NSDateFormatter - 1天不对? [英] NSDateFormatter - 1 day incorrect?

查看:87
本文介绍了NSDateFormatter - 1天不对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在导入日期格式为月/日/年的CSV文件(例如2007年1月21日)。

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

我正在循环使用CSV工作正在进行,但是有些人出现的时间是前一天,时间是23:00?其中一个不起作用的日期如下所示:

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

但是当我在NSLog中输出日期时它有:

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

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

日期:字符串:10/7/2007日期:2007-10-06 23:00:00 GMT

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

我做错了什么?

推荐答案

听起来像你有时区问题,你设置了时区吗?

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

这篇关于NSDateFormatter - 1天不对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆