最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

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

Swift crifan 3501浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.190 seconds, using 22.05MB memory