LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI to convert LabVIEW time to Unix time

Does anybody know of a VI to convert LabVIEW time to Unix time?
0 Kudos
Message 1 of 14
(28,728 Views)
There aren’t any VIs already available to convert LabVIEW time into Unix time. Currently, the LabVIEW Get Date/Time in Seconds.vi returns a time stamp of the current time, measured as the number of seconds that have elapsed since 12:00 a.m., January 1, 1904, Universal time. As far as I know, the unix timestamp is based on seconds since standard epoch of 1/1/1970. The conversion to unix time would not be too difficult; essentially you would just want convert timestamp all to seconds and then subtract the number of seconds from 1904 to 1970.

An alternative approach would be to see if there’s a shared library (or DLL equivalent) on the unix OS that will return the unix time.

Hope this helps. Best of luck!

Kileen
0 Kudos
Message 2 of 14
(28,710 Views)
This could be an entertaining project. I think times are stored based on GMT, then there is an offset local to your computer which puts the sun in the right part of the sky, for where you are. At least it seems that way with Microsoft time. Is Unix time really POSIX time? I see a POSIX manual at the very end of my bookshelf...

Time is number of seconds since midnight January 1, 1970
    Coordinated Universal Time
(GMT). It would be interesting to find out how to discover the timezone offset of the local computer; it seems like its hardware specific.
0 Kudos
Message 3 of 14
(28,708 Views)

I've created a VI that does just this and posted it on the community examples. You can view it at http://decibel.ni.com/content/docs/DOC-3644.

 

Basically to get around the timezone issue that Odd_Modem pointed out it queries the timezone data from the kernel32.dll in windows then subtracts out this offset.

 

Regards,

 

Steven Zittrower

Applications Engineer

National Instruments

http://www.ni.com/support

0 Kudos
Message 4 of 14
(27,982 Views)

StevieZ, I don't believe your method is necessary.  That is, there isn't a "time zone" issue to deal with.  I've attached a VI that demonstrates this.

UNIX_Time_Simple.jpg

Message 5 of 14
(27,634 Views)

Here is a simpler (and OS independent) method to get the timezone offset.

CalcOffset.png

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 6 of 14
(27,607 Views)
Very nice, Ton.  But what I'm attempting to demonstrate is that the timezone offset is not needed if one is simply trying to determine the current Unix (POSIX) time.  All that is needed is to subtract a constant, timezone independent value from the LV timestamp.
Message 7 of 14
(27,563 Views)

ceger wrote:
Very nice, Ton.  But what I'm attempting to demonstrate is that the timezone offset is not needed if one is simply trying to determine the current Unix (POSIX) time.  All that is needed is to subtract a constant, timezone independent value from the LV timestamp.

Indeed and you can determine that offset once and then use it as a simple numeric in all your diagrams.

 

For the curious ones the interesting part that ceger refers to is all at the right border of his VI in the box. What you see there is all that is needed to convert LabVIEW time from its epoch into a different epoch.

Message Edited by rolfk on 10-13-2009 08:09 AM
Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 14
(27,549 Views)

ceger wrote:
Very nice, Ton.  But what I'm attempting to demonstrate is that the timezone offset is not needed if one is simply trying to determine the current Unix (POSIX) time.  All that is needed is to subtract a constant, timezone independent value from the LV timestamp.

Yes I know, I was posting the code to provide a non-os dependent way to get the timezone offset.

Especially since the Windows version came from an NI member.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 9 of 14
(27,543 Views)

Hi,

I need information for convert LV Date/Time to Unix time on sbRIO9631.

I have seen the example, but I have a different time between PC and sbRIO (sbRIO: 2010/04/09 07:22:33 and PC: 2010/04/09 16:22:33).
I need to synchronize the time!

If anyone can help?


Thanks a lot!

 

md71

0 Kudos
Message 10 of 14
(26,813 Views)