How do you get the seconds from epoch in Swift?
You can simply use NSDate's timeIntervalSince1970 function. Note this needs to have Foundation imported.
In a computing context, an epoch is the date and time relative to which a computer's clock and timestamp values are determined. The epoch traditionally corresponds to 0 hours, 0 minutes, and 0 seconds (00:00:00) Coordinated Universal Time (UTC) on a specific date, which varies from system to system.
You can simply use NSDate's timeIntervalSince1970
function.
let timeInterval = NSDate().timeIntervalSince1970
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With