SwiftDate icon indicating copy to clipboard operation
SwiftDate copied to clipboard

timeIntervalSince1970 with Locale

Open adrimarti opened this issue 10 years ago • 3 comments

I do not know how to get the timeIntervalSince1970 with the default Locale of the device.

adrimarti avatar Oct 11 '16 11:10 adrimarti

I'm sorry but I think I can't understand what you try to accomplish.

Want you get the .timeIntervalSince1970 in device's locale? .timeIntervalSince1970 is the absolute number of seconds since 1970 and the value is not related to a specific locale.

If you want to get the .timeIntervalSince1970 from a DateInRegion object you can obtain it using

let secs = dateInRegionObj.absoluteDate.timeIntervalSince1970

malcommac avatar Oct 11 '16 12:10 malcommac

I am using a third part library to represent my data on charts and I must provide the dates on the UNIXTimestamp format. Then, when I try to represent a date, it is shown as 2 hour before date because it is not taking the time with my current Locale.

adrimarti avatar Oct 11 '16 13:10 adrimarti

You can allocate a Date object without using DateInRegion via:

.init(timeIntervalSince1970: TimeInterval)

malcommac avatar Oct 17 '16 18:10 malcommac