【问题标题】:NSDateFormatter is returning wrong Date on iOS 8.3NSDateFormatter 在 iOS 8.3 上返回错误的日期
【发布时间】:2015-04-27 10:44:15
【问题描述】:

我有一个如下的日期格式化程序:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSString *formatStr;
formatStr = @"yyyy-ww"; // WeekOfYear
[dateFormatter setDateFormat:formatStr];

我是这样使用它的:

NSDate *firstDate = [dateFormatter dateFromString:@"2015-01"];

但是,当打印 firstDate 时,它​​显示:

(lldb) po firstDate
2014-12-27 16:00:00 +0000

我不知道我哪里做错了,但我永远不会说 2014-12-27 是 2015 年的第一周。

有人可以帮忙吗?非常感谢!

【问题讨论】:

标签: ios nsdateformatter


【解决方案1】:

在您的设备中转到

设置 > 通用 > 国际 > 日历。 确保已选择公历。

如果选择了公历以外的任何内容,则您的设备将根据该日历将其转换为日期

使用此link 了解 IOS 中的日期格式

【讨论】:

    猜你喜欢
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多