Hello,
I am creating an application that generates a notification (using the Notifications plugin). As we know, it requires to indicate the time in UTC time. For this reason, my App calculates the difference between local time and UTC (this is Spain and right now the UTC / GMT difference is + 2).
In fact, if I try to show the current local time and the current UTC time, it does it correctly. But when trying to calculate the DIFFERENCE between both time uses, it does not do it correctly or I’m making some mistake that I do not know.
We see it with this simple example:
print("Local Time: ", os.date( “*t” ).day, os.date( “*t” ).hour, os.date( “*t” ).min)
print("UTC Time: ", os.date( “!*t” ).day, os.date( “!*t” ).hour, os.date( “!*t” ).min)
This sentences present (correctly) the following output:
Local Time: 27 9 34
UTC Time: 27 7 34
As we can see, the difference of 2 hours is confirmed (9 and 7).
But, if I compute the difference like this:
print("Local secs: ", os.time(os.date( “*t” )), "UTC secs: ", os.time(os.date( “!*t” )), "Dif.: ", os.difftime( os.time(os.date( “*t” )), os.time(os.date( “!*t” )) ) / 3600)
The output is:
Local secs: 1522136070 UTC secs: 1522132470 Dif.: 1
Just only 1 hour!!
Please, I will appreciate any help in this.
Thanks!
J.M.