我的 DateFormatting 有什么问题?
What is wrong with my DateFormatting?
这是我的代码
let fmt = NSDateFormatter()
fmt.dateFormat = "yy/MM/dd (EEE)"
这是我的数据 (selectedNotifications)
2015-12-16 10:26:31 +0000
当我这样格式化时,
cell.receivedDate.text = "From XXX on " + fmt.stringFromDate(selectedNotificaitons.createdAt)
它让我看到了这个
From XXX on 58/12/16 (Wed)
我怎么了?为什么年份是 58 而不是 15
您上面发布的代码是正确的。我在 playground 上试过,结果是正确的输出
所以错误就出在你的selectedNotificaitons.createdAt
。打印 createdAt 属性 并检查它
尝试将区域设置设置为 en_US_POSIX
以告知 Swift 使用公历。
fmt.locale = NSLocale(localeIdentifier: "en_US_POSIX")
这是我的代码
let fmt = NSDateFormatter()
fmt.dateFormat = "yy/MM/dd (EEE)"
这是我的数据 (selectedNotifications)
2015-12-16 10:26:31 +0000
当我这样格式化时,
cell.receivedDate.text = "From XXX on " + fmt.stringFromDate(selectedNotificaitons.createdAt)
它让我看到了这个
From XXX on 58/12/16 (Wed)
我怎么了?为什么年份是 58 而不是 15
您上面发布的代码是正确的。我在 playground 上试过,结果是正确的输出
所以错误就出在你的selectedNotificaitons.createdAt
。打印 createdAt 属性 并检查它
尝试将区域设置设置为 en_US_POSIX
以告知 Swift 使用公历。
fmt.locale = NSLocale(localeIdentifier: "en_US_POSIX")