最新消息:VPS服务器又从fzhost.net换回Linode了,主题仍用朋友推荐的大前端D8

[已解决]swift时间戳转换为日期时间

Swift crifan 128浏览 0评论
let timestampInt64 = 1449805150184

func parseDateFromTimestamp(timestampValue:Int) -> NSDate {
   
let parsedDate:NSDate = NSDate(

    return parsedDate

}

搜:

swift timestamp to date

ios – Convert timestamp into NSDate swift? – Stack Overflow

Swift: how to create a date time stamp and format as ISO 8601, RFC 3339, UTC time zone? – Stack Overflow

Swift convert unix time to date and time – Stack Overflow

【总结】

import UIKit

let timestampIntInMsec = 1449805150184

func parseDateFromTimestamp(timestampIntInMsec:Int) -> NSDate {
   
print("timestampIntInMsec=\(timestampIntInMsec)")
   
let timestampDoubleInSec:Double = Double(timestampIntInMsec)/1000
   
print("timestampDoubleInSec=\(timestampDoubleInSec)")
   
let parsedDate:NSDate = NSDate(timeIntervalSince1970: NSTimeInterval(timestampDoubleInSec))
   
print("parsedDate=\(parsedDate)")
   
   
return parsedDate
}

parseDateFromTimestamp(timestampIntInMsec)

输出:

timestampIntInMsec=1449805150184
timestampDoubleInSec=1449805150.184
parsedDate=2015-12-11 03:39:10 +0000

转载请注明:在路上 » [已解决]swift时间戳转换为日期时间

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
16 queries in 0.210 seconds, using 9.77MB memory