My Sqlite database has a 'Time' field of type 'INTEGER'
I write Unix time (epoch) to it from a C++ windows service like this:
insert into ServicesData (Time, ...) values (((strftime('%s', 'now') - strftime('%S', 'now') + strftime('%f', 'now')) * 1000), ...);
(see https://stackoverflow.com/a/20478329/460084 "grabbing the number of seconds since the Unix Epoch (%s), subtracting the number of seconds in the current time (%S), adding the number of seconds with decimal places (%f), and multiplying the result by 1000 to convert from seconds to milliseconds")
I then read the date from a .NET Core 3.1 console app like this:
public class ServicesData {
[Key]
public long Time { get; set; }
...
public string ToString() {
string res="";
var time = DateTimeOffset.FromUnixTimeMilliseconds(Time).DateTime;
res+= time.ToString("dd/MM/yy HH:mm:ss") + " ";
... return res;
}
}
I now do a query from my .NET app on the same box and verify that the integer value of ServicesData.Time
is the same as that on the database using DB Browser for SQLite
However on calling ToString()
the resultant displayed date is one hour FW of the time when the entry was written to the DB !
Why aren't the dates matching ?
(note I tried replacing FromUnixTimeMilliseconds(Time).DateTime
with FromUnixTimeMilliseconds(Time).UtcDateTime;
but got the same result)