NSDateFormatter - 1 天不正确?

发布于 2024-09-25 23:40:34 字数 525 浏览 0 评论 0原文

我正在导入日期格式为月/日/年的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏九 2024-10-02 23:40:34

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文