c_w_k Posted December 21, 2009 Report Share Posted December 21, 2009 Hello, One of my many questions is on creating a timestamp in LabVIEW.... I'm getting a value from a C++ DLL that returns the seconds since 01/01/1970 ("epoch"). I'm then trying to use the LabVIEW "SecondsToDate/Time" vi to convert this to a readable time format. When I do this the date is off by 300 years.....is there a trick to doing this? Is the labVIEW "SecondsToDate/Time" vi capable of converting time from 01/01/1970 or does it use a different date to convert from?? I'm wondering if it may be easier to create a timestamp just by using labVIEW instead of trying to convert the epoch variable that is returned by the C++ dll? For example my vi is gathering data constantly from a device, instead of taking the epoch variable from the C++ code I think I could possibly create a labVIEW time stamp each time the vi collects data........my first choice would be to convert the epoch variable that is provided from the C++ DLL..... so any help on taking a C++ variable and converting it into a timestamp in LabVIEW would be greatly appreciated... I've attached below, the code that I have so far.... -CK Quote Link to comment
ned Posted December 21, 2009 Report Share Posted December 21, 2009 I'm getting a value from a C++ DLL that returns the seconds since 01/01/1970 ("epoch"). I'm then trying to use the LabVIEW "SecondsToDate/Time" vi to convert this to a readable time format. When I do this the date is off by 300 years.....is there a trick to doing this? Is the labVIEW "SecondsToDate/Time" vi capable of converting time from 01/01/1970 or does it use a different date to convert from?? If you read the help for the LabVIEW Seconds to Date/Time, you'll see that LabVIEW's "epoch" date is 12:00 a.m., Friday, January 1, 1904. You can determine the number of seconds between your epoch date and LabVIEW's, then add that amount before doing the conversion. Also make sure to use a numeric format with enough bits to store your number of seconds, taking LabVIEW's epoch date into account. Quote Link to comment
c_w_k Posted December 21, 2009 Author Report Share Posted December 21, 2009 1970 epoch = 21600 (hopefully these are right, found them on a website that calculates epoch dates) 1904 epoch = -2082823200 ====================== difference of -2082844800 so I added -2082844800 to the variable that is sent in from my C++ DLL......and I now get a year of 2246, which isn't as bad as being off by 300 years....but i've still got a ways to go.....the DLL is getting the value from a device simulator so I wonder if it is sending a bogus number..... Quote Link to comment
Cat Posted December 22, 2009 Report Share Posted December 22, 2009 so I added -2082844800 to the variable that is sent in from my C++ DLL......and I now get a year of 2246, which isn't as bad as being off by 300 years....but i've still got a ways to go.....the DLL is getting the value from a device simulator so I wonder if it is sending a bogus number..... 2082844800 is within an hour (+/- for DST). I use 2082848400 for talking with Linux/Solaris systems and that works correctly. Do you know for sure that your dll is returning the correct value? Quote Link to comment
Phillip Brooks Posted December 22, 2009 Report Share Posted December 22, 2009 (edited) If the remote device is sending you a value that is the number of seconds since 1/1/1970 00:00:00, then create a timestamp constant on the block diagram, and set the value to 1/1/1970 00:00:00. Use the add primitive to combine the epoch with the DLL seconds. LabVIEW tip: easy relative timestamp calculations Edited December 22, 2009 by Phillip Brooks 1 Quote Link to comment
Rolf Kalbermatter Posted December 22, 2009 Report Share Posted December 22, 2009 1970 epoch = 21600 (hopefully these are right, found them on a website that calculates epoch dates) 1904 epoch = -2082823200 ====================== difference of -2082844800 so I added -2082844800 to the variable that is sent in from my C++ DLL......and I now get a year of 2246, which isn't as bad as being off by 300 years....but i've still got a ways to go.....the DLL is getting the value from a device simulator so I wonder if it is sending a bogus number..... How big is your number then? As you can see 66 years (1970 - 1904) corresponds roughly to 2*10^9 seconds. From your 300 year difference I would guess you are not getting the number of seconds but rather something else such as the number of ms, since that ominous 1970 date. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.