My issue is trying to convert a Date Picker result into a unix timestamp. My client is adamant that it'd be saved as a unix timestamp into Firebase database. Im also quite new to the swift so...
let myTimeStamp = NSDate(timeIntervalSince1970: self.datePicker?.date)
this is the result of datePicker: 2016-12-03 00:56:00 +0000 This is the error: Cannot convert value of type 'Date?' to expected argument type 'TimeInterval' (aka 'Double')
Please help sirs & ma'ams!
You already have the Date
. Since you want the timestamp, call:
let myTimeStamp = self.datePicker?.date.timeIntervalSince1970
myTimeStamp
will be an NSTimeInterval
with a value in Unix time.
Including swift 5+ **Pass date like yourDatePicker.date **
func getTimeStampFromDate(date: Date) -> String {
return String(format: "%.0f", (date.timeIntervalSince1970 * 1000))
}
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