将一天中的当前时间减少到毫秒错误
Getting current time of day down to milliseconds error
我一直在尝试以 hour:minute:second 格式访问一天中的时间,但是所有这些
println(CFTimeZoneCopySystem())
println(CFTimeZoneCopyDefault())
println(gettimeofday)
println(CACurrentMediaTime)
打印是
America/New_York (EDT) offset -14400 (Daylight)
America/New_York (EDT) offset -14400 (Daylight)
(Function)
(Function)
我不明白为什么这些只是打印出“(函数)”,我也不确定 14400 是什么时间格式。我希望能够访问跨蓝牙设备准确的内容。所以这就是为什么我更愿意访问毫秒。我知道还有另一个与此类似的问题,但我认为他们没有收到这篇文章,而且我不明白 objective-C
您可以使用以下代码:
let formatter = NSDateFormatter()
//formatter.timeZone = NSTimeZone(forSecondsFromGMT: 0) // you can set GMT time
formatter.timeZone = NSTimeZone.localTimeZone() // or as local time
formatter.dateFormat = "HH:mm:ss.SSS"
println(formatter.stringFromDate(NSDate()))
输出:“05:57:26.123”
我一直在尝试以 hour:minute:second 格式访问一天中的时间,但是所有这些
println(CFTimeZoneCopySystem())
println(CFTimeZoneCopyDefault())
println(gettimeofday)
println(CACurrentMediaTime)
打印是
America/New_York (EDT) offset -14400 (Daylight)
America/New_York (EDT) offset -14400 (Daylight)
(Function)
(Function)
我不明白为什么这些只是打印出“(函数)”,我也不确定 14400 是什么时间格式。我希望能够访问跨蓝牙设备准确的内容。所以这就是为什么我更愿意访问毫秒。我知道还有另一个与此类似的问题,但我认为他们没有收到这篇文章,而且我不明白 objective-C
您可以使用以下代码:
let formatter = NSDateFormatter()
//formatter.timeZone = NSTimeZone(forSecondsFromGMT: 0) // you can set GMT time
formatter.timeZone = NSTimeZone.localTimeZone() // or as local time
formatter.dateFormat = "HH:mm:ss.SSS"
println(formatter.stringFromDate(NSDate()))
输出:“05:57:26.123”