LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert UTC time to local without DST adjustment

Hi, I would like to convert a UTC time to a local time without the DST adjustment.  Attached is an example VI that demonstrates the issue I have.  When the Time Zone is set from 0-6 the local time is what I would expect.  However, when the time zone is to 7 or greater there is one hour added to the local time for DST.  Is there a way to make it so that there is not a DST adjustment?

 

Thanks in advance for your help!!

 

Jeff

0 Kudos
Message 1 of 17
(586 Views)

Something like this may be:

 

daytime_snippet.png

 

I guess more elegant conversion from UTC exists, but wasn't unable to get it in LabVIEW.

 

0 Kudos
Message 2 of 17
(543 Views)

Thanks for looking into this.  Unfortunately I see the same problem with your example VI.  Here's the problem:

 

UTC:  2024-03-09T19:00Z

 

TZ=+6:00

Local Time:  2024-03-10T01:00Z

 

TZ=+7:00

Local Time:  2024-03-10T03:00Z

 

You can see that when the TZ is changed to +7:00 there is a one hour DST shift.  I would like the the local time to be 2024-03-10T02:00Z.

0 Kudos
Message 3 of 17
(536 Views)

Hi JHess,

 


@JHess wrote:

TZ=+7:00

Local Time:  2024-03-10T03:00Z

 

You can see that when the TZ is changed to +7:00 there is a one hour DST shift.  I would like the the local time to be 2024-03-10T02:00Z.


Did DST kick in on March 10th for your local computer regional setting?

Then local time 2024-03-10T03:00 is basically the same as 2024-03-10T02:00...

 

One more question: why/how is 2024-03-10T03:00Z a "local time" for "TZ=+7"???

"Z" usually is (non-local) UTC time aka TZ=0!?

Or do you need 2024-03-10T02:00+07:00 instead?

Does your timestamp indicator show local or UTC time?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 17
(530 Views)

@JHess wrote:

Thanks for looking into this.  Unfortunately I see the same problem with your example VI.  Here's the problem:

 

UTC:  2024-03-09T19:00Z

 

TZ=+6:00

Local Time:  2024-03-10T01:00Z

 

TZ=+7:00

Local Time:  2024-03-10T03:00Z

 

You can see that when the TZ is changed to +7:00 there is a one hour DST shift.  I would like the the local time to be 2024-03-10T02:00Z.


Ah, OK, got this. Then may be something like this (still not elegant):

Screenshot 2024-03-12 17.26.33.png

 

But when we will proceed to the next Zone, its will be 03:00 again:

 

Screenshot 2024-03-12 17.27.47.png

Is that what you're looking for?

 

There are also ConvertTime methods exists which intended for such conversion, but was unable to get it running because of this:

Screenshot 2024-03-12 17.32.17.png

0 Kudos
Message 5 of 17
(518 Views)

The LabVIEW Timing functions "Date/Time to Seconds" and "Seconds to Date/Time" say that they can convert between "local" and UTC Time, and can (separately) handle DST on (1) or off (0).  I haven't played with these in years (> 10), but if they, indeed, work correctly, this seems a simple solution to this question.

 

Bob Schor

0 Kudos
Message 6 of 17
(505 Views)

@Bob_Schor wrote:

The LabVIEW Timing functions "Date/Time to Seconds" and "Seconds to Date/Time" say that they can convert between "local" and UTC Time, and can (separately) handle DST on (1) or off (0).  I haven't played with these in years (> 10), but if they, indeed, work correctly, this seems a simple solution to this question.

 

Bob Schor


I don't think so, Bob, because the conversion needs to be done for specific Time Stamp in specific Zone (which is differ from currently used Zone in OS). What author need is something like this, I guess:

 

Converting UTC to a designated time zone

 

DateTime timeUtc = DateTime.UtcNow;

   TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
   DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone);
   Console.WriteLine("The date and time are {0} {1}.",
                     cstTime,
                     cstZone.IsDaylightSavingTime(cstTime) ?
                             cstZone.DaylightName : cstZone.StandardName);

 

0 Kudos
Message 7 of 17
(497 Views)

Hi Bob, I believe Andrey is right.  I tried using the DST feature in the "Date/Time to Seconds" and got the same result.  I also tried disabling the "Adjust for daylight saving time automatically" on my PC thinking maybe LabView uses the system clock but that didn't help either.  This seems like it should be a simple thing to do but I am just stumped.  I really appreciate the ideas/help from all of you.

0 Kudos
Message 8 of 17
(489 Views)

Hi JHess,

 

maybe you need to follow some ISO8601 rules?

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 17
(481 Views)

Hello, Gerd.

 

     Where did you get the ISO8601 functions?  I just "asked Google", and it found an "Epoch Date & Time by OpenG" offering on VIPM that I hadn't noticed (or downloaded), but the function icons look slightly different from the ones you showed.

 

     I remember last year at NI-Connect trying to write an analysis routine for some EEG data I had recorded with Time-stamp info.  I wanted to be able to look "25 seconds" after the start of recording, or (alternatively) starting at "12:14 pm".  I had some "real data" I was using to test my routine, but I was "off by an hour" when I tried to make it work.  Duh, I was sitting in Austin, and the data were taken on the East Coast ...

 

Bob Schor

 

0 Kudos
Message 10 of 17
(458 Views)