NSDate() or Date() shows the wrong time

后端 未结 2 1975
走了就别回头了
走了就别回头了 2020-11-22 10:51

When I try to log the current date:

print(NSDate())

or

print(Date()) 

(in Swift 3)

Or any date o

2条回答
  •  余生分开走
    2020-11-22 11:11

    A simple way to correct the Date for your timezone would be to use TimeZone.current.secondsFromGMT()

    Something like this for a local timestamp value for example:

    let currentLocalTimestamp = (Int(Date().timeIntervalSince1970) + TimeZone.current.secondsFromGMT())

提交回复
热议问题