How to calculate seconds elapsed since 00:00:00 GMT January 1, 1970?
Joe Hebert
Posts: 2,159
Does anyone know how take the current date and time and calculate the number of seconds elapsed since 00:00:00 GMT January 1, 1970? The value is expressed in 4 bytes.
I also need to figure out the inverse, given 4 bytes (the number of seconds elapsed?) convert it to a time and date value.
If anyone has written such functions or can anyone point me in the right direction, I?d really appreciate it.
TIA
I also need to figure out the inverse, given 4 bytes (the number of seconds elapsed?) convert it to a time and date value.
If anyone has written such functions or can anyone point me in the right direction, I?d really appreciate it.
TIA
0
Comments
My TimeSync module does that. I have those to support the NTP (network time protocol code) where the time comes back as seconds since January 1st, 1970. It's up on source forge (and is used in i!-TimeManager as well).
You can fetch the sources to the TimeSync module up on SourceForge:
http://sourceforge.net/projects/netlinx-modules/
That will do EXACTLY what you want. Cut and paste the relevant routine from TimeSync.axs into a module of your choice.
-- Jeff
I must be missing something. I downloaded TimeSync-1.0.zip and extracted it, however, there is no TimeSync.axs in the zip. There is an include file named TimeSyncMod.axi. I looked through each file in the zip but don't see any source to do the time conversion. Any ideas?
Thanks,
The .zip file you downloaded was a BINARY source file. I've learned that it's easier to distribute binary, as the source is more involved to build (you need bits of syslog - at least the .axi file, etc).
Look here:
http://cvs.sourceforge.net/viewcvs.py/netlinx-modules/NetLinx-Modules/TimeSync/
This will take you to the TimeSync source code.
Hope that helps. Note that my code handles leap years as well.
-- Jeff
Doing the reverse:
It is not very well documented, but fire away if you have a question. One thing you need to do in the CALLING code is to define the functions you are actually using. The .axi figures out by itself which internal ones are needed if any. For example: In any case Netlinx will remind you some function is not defined. Alternatively uncomment all such defines in the .axi. I do this to keep the code size down, I am reaching 1MB and the limit of my old Netlinx card...
Credit where credit is due: part of this code is derived from Jeff's code on sourceforge, in particular the stuff dealing with calculations of seconds since 1900...
Hope this helps
Fred