How to calculate seconds elapsed since 00:00:00 GMT January 1, 1970?
Joe Hebert
Junior Member
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
Comments
-
I've got that ...
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 -
Thanks, Jeff. I'll check it out.
-
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, -
I think I have it figured out for the most part. I just need to determine the best way to handle leap years. Thanks, anyhow.
-
Hi, sorry for the lack of information.
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 -
Here's a little utility .axi defining a "DateTime" structure with associated functions working on it, one of them being the difference in seconds between two dates.
STACK_VAR _DateTime now, y0; STACK_VAR LONG theResult; DateTime_Now(now); DateTime_SetDate(y0, 1970, 1, 1) DateTime_SetTime(y0, 0, 0, 0) theResult = DateTime_GetDiffSeconds(now, y0)
Doing the reverse://assume theSecs contains the seconds... STACK_VAR _DateTime theResult; DateTime_SetDate(theResult, 1970, 1, 1) DateTime_SetTime(theResult, 0, 0, 0) DateTime_SecondOffset(theResult, theSecs) // Now use theResult, f.e. using DateTime_GetDateTimeString()...
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:#define __DATETIME_SecondOffset__
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 -
Thanks for your help Jeff and Fred.
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums