LabVIEW

cancel
Showing results 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?

Jeff

Message 1 of 17
(710 Views)

Re: How to convert UTC time to local without DST adjustment

Something like this may be:

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

Message 2 of 17
(667 Views)

Re: How to convert UTC time to local without DST adjustment

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.

Message 3 of 17
(660 Views)

Re: How to convert UTC time to local without DST adjustment

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
Message 4 of 17
(654 Views)

Re: How to convert UTC time to local without DST adjustment

@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):

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

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:

Message 5 of 17
(642 Views)

Re: How to convert UTC time to local without DST adjustment

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

Message 6 of 17
(629 Views)

Re: How to convert UTC time to local without DST adjustment

@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);
``````

Message 7 of 17
(621 Views)

Re: How to convert UTC time to local without DST adjustment

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.

Message 8 of 17
(613 Views)

Re: How to convert UTC time to local without DST adjustment

Hi JHess,

maybe you need to follow some ISO8601 rules?

Best regards,
GerdW

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

Re: How to convert UTC time to local without DST adjustment

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

Message 10 of 17
(582 Views)