LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

EPOC time

how can I obtain the epoc time from jan 1 1970.  the time function runs the current time in hours, minutes,seconds.

 

0 Kudos
Message 1 of 11
(5,613 Views)

I'm not aware of a native function in CVI that returns the time from epoch; what you can do is differenziate between the current time and the epoch and convert the result to seconds. Something like this:

#include <utility.h>

static CVIAbsoluteTime now, epoch; static CVITimeInterval difference; static double TimeFromEpoch; GetCurrentCVIAbsoluteTime (&now); CVIAbsoluteTimeFromLocalCalendar (1970, 1, 1, 1, 0, 0, 0, &epoch); SubtractCVIAbsoluteTimes (now, epoch, &difference); CVITimeIntervalToSeconds (difference, &TimeFromEpoch);

TimeFromEpoch corresponds to the Unix time given by online calculators (note that I have added 1 hour to compensate for the daylight savings time that is active in my country).

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 11
(5,608 Views)

Sorry for the late response.  I tried the code and compared to the epoc time from Visual studio and online and it looks like the CVI epoc time is a few days behind.  Any suggestions?

0 Kudos
Message 3 of 11
(5,387 Views)

I have no VS installed here but I have compared the time calculated as above with the one shown on this epoch converter and always hade a negligible difference (mainly due to my reaction time I suppose).

Which site do you checked the calculated time against?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 11
(5,383 Views)
0 Kudos
Message 5 of 11
(5,377 Views)

I don't understand your observation about the differences in epoch time: both sites give identical epoch time, the same as CVI functions. Where and how do you observe such difference?

 

Screenshot 2016-05-03 00.33.59.png



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 11
(5,368 Views)

Sorry for the late response.  I read 1463400922 from the CVI function calls and 1463418934 from http://www.epochconverter.com/ .  I have some time difference from executing the code and viewing the page but it should only be a few seconds.

 

 

0 Kudos
Message 7 of 11
(5,210 Views)

May the difference be due to your timezone? NIBTF refers to UTC, you may be calculating the epoch time referred to your local time.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 11
(5,208 Views)

I was thinking the same thing.  Does the function compensate for your time zone?  I am on EST.

0 Kudos
Message 9 of 11
(5,201 Views)

Yes, the function CVIAbsoluteTimeFromLocalCalendar effectively uses the local calendar, which includes time zone informations (but not DST even if in effect)

This is the reason for the 5-hour shift between the epoch time referred to GMT given by the site you linked and CVI results.

And I must correct the assertion in my first post: the 1-hour difference I compensated in the code is for me leaving in CET, not for DST active in this period.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 10 of 11
(5,196 Views)