- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
代码摘录如下:
func mapping(map: Map) {
time <- (map["time"], TransformOf<Date, String>(fromJSON: {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "HH:mm:ss"
//dateFormatter.timeZone = TimeZone(abbreviation: "EEST")
if let argument = $0 {
let date = dateFormatter.date(from: argument)
return dateFormatter.date(from: argument)
}
return nil
}}
$0
是带有"22:12:00"
的字符串。我输入“let date”以查看它返回的内容,结果为零。我在这里查找了格式代码:http://waracle.net/iphone-nsdateformatter-date-formatting-table/
代码应该实际工作。我做错了什么?
编辑:添加了整个功能
EDIT2:我刚刚注意到它在 iPhone 7 iOS 10.1 模拟器上运行正常,但在我的 iPod 10.1.1 (2016) 上返回 nil。这太奇怪了。
最佳答案
来自 Technical Q&A QA1480 – NSDateFormatter and Internet Dates (强调):
On the other hand, if you're working with fixed-format dates, you should first set the locale of the date formatter to something appropriate for your fixed format. In most cases the best locale to choose is "en_US_POSIX", a locale that's specifically designed to yield US English results regardless of both user and system preferences.
这将防止日期被解释为用户的区域设置:
let dateFormatter = DateFormatter()
// Set the locale first ...
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
// ... and then the date format:
dateFormatter.dateFormat = "HH:mm:ss"
// ...
另见 What is the best way to deal with the NSDateFormatter locale "feechur"? .
关于ios - DateFormatter 不返回 "HH:mm:ss"的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40692378/
我的日期时间格式字符串是:yyyy-MM-dd'T'HH:mm:ss.SSSZ 我正在使用 Joda Time 中的 DateTimeFormatter 以上述格式打印我的日期。 现在,将日期视为 2
这个问题已经有答案了: Getting date from [NSDate date] off by a few hours (3 个回答) 已关闭 5 年前。 我对 Date 进行了扩展,返回格式化
先决条件 在手机设置中设置时区 GMT+13(法莱、托克劳)。 实现 extension Date { func formatForDto() -> String { let
我经常在代码中使用 DateFormatter 并且没有发现任何问题,但后来我决定测试一个类进行大量迭代 - 我注意到一个巨大的内存泄漏。 泄漏的原因是 DateFormatter。 简单代码: va
这个问题已经有答案了: want current date and time in "dd/MM/yyyy HH:mm:ss.SS" format (11 个回答) Change the format
我正在尝试将不带时区值(例如“31.05.2015”)的字符串转换为 NSDate。 我的 DateFormatter 有什么问题?它返回日期 2015-05-31 22:00:00 +0000当我尝
这个问题已经有答案了: NSDateFormatter show wrong year (1 个回答) 已关闭 3 年前。 我尝试格式化我的 UTC 日期,但结果似乎非常错误 日期格式化程序:
这个问题在这里已经有了答案: NSDate Format outputting wrong date (5 个答案) Getting date from [NSDate date] off by
我一直在使用以下代码来格式化日期值: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setLoca
这个问题在这里已经有了答案: Getting date from [NSDate date] off by a few hours (3 个答案) 关闭 5 年前。 我对返回格式化字符串的 Date
我从字符串中得出的日期总是 nil,我不知道为什么。 func getBirthdate() -> Date? { let formatter = DateFormatter()
我是 iOS 的新手,我想在我的约会中增加几毫秒,比如 (5)。我使用了下面的代码,但我没有得到我正在使用的确切日期 let str_TimeStamp = "2017-08-09 10:26:30.
我的 DateFormatter 有问题。 我的 iOS 应用程序与服务器通信并使用 If-Modified-Since header 和使用以下格式化程序创建的日期: modifiedSinceDa
首先要提前致谢。我已经使用 iOS/Swift 多年,这是我第一次看到这种奇怪的行为。这是代码: let dateFormatter = DateFormatter() dateFormatter.d
这个问题在这里已经有了答案: NSDateFormatter show wrong year (1 个回答) 关闭 6 年前。 我有以下代码: var components = DateCompon
在我的 Java 应用程序中,我使用 DateFormat 实例来解析日期输入。 DateFormat fmt; fmt = DateFormat.getDateInstance(DateFormat
代码: let isoDate = "1981-02-20T10:44:00+0800" let dateFormatter = DateFormatter() dateFormatter.timeZ
有谁知道 Java 中的 DateFormatter 不是那么挑剔?我的意思是我可以为它提供多种格式的日期,如果我提供它这样的格式: yyyy-MM-dd HH:mm:ss Z 用户可以输入: 201
我已经阅读了多篇关于此的文章,其中大部分是由于未设置特定时区而系统获取了当前时区。我的场景略有不同并给出了意想不到的结果,所以我会尝试详细解释。 我正在处理一个返回日期的后端,该日期分为日期和时间,存
我试图以我设备的语言显示格式化日期,但它一直以英语显示(即使设备设置为葡萄牙语)。 在我的 ViewController 中我创建了一个日期: let todaysDate: Date = Date(
我是一名优秀的程序员,十分优秀!