04-04-2016 06:40 AM
how can I obtain the epoc time from jan 1 1970. the time function runs the current time in hours, minutes,seconds.
04-04-2016 07:46 AM
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).
05-02-2016 10:04 AM
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?
05-02-2016 10:51 AM - edited 05-02-2016 10:52 AM
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?
05-02-2016 11:01 AM
05-02-2016 05:37 PM
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?
05-16-2016 12:16 PM
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.
05-16-2016 03:24 PM
May the difference be due to your timezone? NIBTF refers to UTC, you may be calculating the epoch time referred to your local time.
05-16-2016 05:41 PM
I was thinking the same thing. Does the function compensate for your time zone? I am on EST.
05-16-2016 06:34 PM
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.