Xojo.Core.Date.SecondsFrom1970

From Xojo Documentation

Read-Only Property (As Double )
DoubleValue = aXojo.Core.Date.SecondsFrom1970

Supported on Mobile (iOS).

The number of seconds since the first instant of 1 January 1970, GMT.

Notes

This value is also referred to as the Unix epoch, Unix time or Unix timestamp.

You can save this value (in a file or database, for example) and use a Constructor to create a new Date instance for it. Negative values indicate seconds before the first instant of 1 January 1970, GMT.

Sample Code

Get the seconds since 1970 and use it to create a new date:

Var d1 As Date = Xojo.Core.Date.Now
Var seconds As Double = d1.SecondsFrom1970
Var d2 As New Date(seconds, Xojo.Core.TimeZone.Current)
// Both d1 and d2 have the same date value

Calculate the number of days between two dates:

Var d1 As New Xojo.Core.Date(2018, 8, 1, Xojo.Core.TimeZone.Current)
Var d2 As New Xojo.Core.Date(2015, 3, 1, Xojo.Core.TimeZone.Current)
// Subtract seconds and convert seconds to days
Var days As Double = (d1.SecondsFrom1970 - d2.SecondsFrom1970) / (24 * 60 * 60)