LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the daylight saving time parameter from the time function?

Hi, there,
 
I am using labwindow 7.1. Every time the daylight saving time change, I ran into problem of sych the clock to my PC clock correctly. I have to manually adjust one of the parameter in the program that I wrote in CVI to correct this problem. Is there any function I can use in the CVI that can tell whether or not daylight saving time has been changed?
 
Currently I am using time( &pc_time) to get the over all second of the PC time, then use the difftime(time_t, time_t) function to get the time gap and do the sychronization. There are twice in a year my synchonization is off one hour either earlier or later because the DST. Anyone there can help?
 
Thanks,
 
Dora 
0 Kudos
Message 1 of 5
(4,257 Views)
Hello Dora.

You can use Windows SDK functions to accomplish this (refer to the SDK Help):
  • Call GetSystemTime() to get the current (UTC / GMT) time information in a SYSTEMTIME struct
  • Call SystemTimeToTzSpecificLocalTime() to convert to local time, adjusted for Daylight Saving if required
  • To check whether Daylight Saving Time is in force, call GetTimeZoneInformation()
  • Use GetTimeFormat() / GetDateFormat() to create a string representation of the current time
Note that CVI's Utility library provides a GetSystemTime() function; check the CVI Help for precautions you may need to take.

Regards,
Colin.
Message 2 of 5
(4,245 Views)
Hi Dora,
to check if we are in DST  you can use localtime () function: it returns a tm struct whose tm_isdst field is true if we are in daylight saving time. Copy these lines in interactive window and execute them, next you can see in the debug window the result and examine in variables window the content of struct fields.
 
#include <ansi_c.h>
#include <utility.h>
static long   now;
static struct tm *tm;
 
time (&now);
tm = localtime (&now);
DebugPrintf ("Are we in DST? %s\n", tm->tm_isdst ? "Yes" : "No");
 
On the other hand, depending on your needs you may want to consider Timer () function as the source of your program timing: the value returned bu this function does not follow DST changings, since it counts actual seconds from program start. It rolls over only every 49 days and some but it remains consistent even after rollover, so it may be a possible reference value for you.


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 3 of 5
(4,232 Views)
Thanks a lot, Roberta, your reply is really helpful. I use the tm_isdst to find whether it is DST, it is that simple and easy! My problem is fixed now. Thank you so much!
 
Dora
0 Kudos
Message 4 of 5
(4,213 Views)

You're welcome!

Roberto   ( Smiley Wink )



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 5 of 5
(4,196 Views)