Eyzuky Eyzuky - 3 years ago 160
Swift Question

Add current timezone difference to timeintervalsince1970 in swift

I have an API call that asks me to convert dates to

in ms and they also want me to add the correct time zone difference. So my code is at the moment:

if let timeStamp = incident?.publishedTimeStamp as Date? {
let roundedDown = Int(timeStamp.timeIntervalSince1970 * 1000)
publishedDate = String(roundedDown)

This gives me a number that if I insert it in here:

I get this result:

Now as you can see, the
time (the top result) is what I at the moment achieve. I need to add enough ms so that the Your time zone section would be in the
section. I hope this makes sense.

So how can I get the number in ms that represents the difference between the current time zone from
so I can sum it with my current result?

Answer Source
var roundedDown = Double(TimeZone.current.secondsFromGMT(for: timeStamp)) + timeStamp.timeIntervalSince1970
roundedDown *= 1000
publishedDate = String(Int(roundedDown))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download