LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get time of different timezone(s) with Daylight Savings

Solved!
Go to solution

Hi community,

 

I am in the EU and according to my PC's clock (timezone - CET) I'd like to know what is the time in the US (timezone EDT). This seems to be an easy task, but as CET and EDT changes daylight savings in a different date of the year, its not as easy as simply using an offset. Moreover later my application needs to know the time in several other timezones as well, so I need sort a generic solution.

 

I know how to check the diff between my local time and UTC, but that doesnt help too much, as I dont know how to check the diff between EDT and UTC.

 

Any ideas?

 

 

 

0 Kudos
Message 1 of 12
(2,321 Views)

This is the kind of thing which you want to delegate to something else, if possible. Specifically, Windows should have something built in with the TimeZoneInfo class:

 

Time zones.png

 

This code doesn't actually work (throws an error) and I didn't bother to check why, but it should probably put you on the right path and you can then post the correct code back. You can use a combo box to select the relevant time zone.

 


___________________
Try to take over the world!
0 Kudos
Message 2 of 12
(2,291 Views)

EDIT: whooops... this may not be true and the function may exists in older versions. Let me check

------------------

 

Thanks mate, it seems that this can be an elegant solution once its finished. I have tried to reproduce the code, but I just realized that the System.TimeZoneInfo object is introduced with .net 4.5 which I dont have, and I very much prefer not installing it if I have any other option.

 

What I find odd is that a feature like this must come with windows as if I change the timezone of the PC's clock then it immediately know if we are in DST.

 

Thanks again, and if I find no other solution then I will install .net 4.5

 

Until that I keep looking for any other solution.

0 Kudos
Message 3 of 12
(2,278 Views)

Most likely the actual functionality is in fact in the Windows kernel in the SystemTimeToTzSpecificLocalTime() and TzSpecificLocalTimeToSystemTime() and the .Net component simply access that API to do it's work. That said before Windows 7 the API wasn't capable of handling more than one timezone at the same time. And it wasn't capable of handling different DST start and end times, as would be necessary if you want to go more than a few years back in time, since there have been several DST period changes in the past.

Rolf Kalbermatter
Averna BV
LabVIEW ArchitectLabVIEW ChampionLabVIEW Instructor
0 Kudos
Message 4 of 12
(2,269 Views)

Thanks mate. Any chance you having the implementation somewhere? I am not familiar with calling such stuff from labview.

 

thanks.

0 Kudos
Message 5 of 12
(2,264 Views)

@1984 wrote:
I have tried to reproduce the code, but I just realized that the System.TimeZoneInfo object is introduced with .net 4.5 which I dont have, and I very much prefer not installing it if I have any other option.

 

What I find odd is that a feature like this must come with windows as if I change the timezone of the PC's clock then it immediately know if we are in DST.


The MSDN page says it should be in 3.5 and up. I have 4.0 installed. You should be able to simply get the code by saving the image to your HD and then dragging it into a block diagram, which should convert it to code you can use.

 

As for the OS, the reason I suggested that is that time zones often change and have all kinds of special cases. Using something which already works should get you that for free.

 

Looks like there are some details here, but I haven't read it - https://msdn.microsoft.com/en-us/library/bb397769%28v=vs.110%29.aspx


___________________
Try to take over the world!
Message 6 of 12
(2,253 Views)
Solution
Accepted by topic author 1984

Alright... I didnt know that a snippet can be converted to code. I learn something everyday Smiley Happy

 

I think I have figured the way to get rid of the error message. I assume that I did exactly what your original function was supposed to do, but divided it to two more elementary steps. It seems to work fine now.

 

Thanks for helping me out with this!

 

lvcode.png

0 Kudos
Message 7 of 12
(2,232 Views)

I would highly recommend not using the numeric constants for selecting the IDs. I'm assuming that the list of IDs is not always going to be in the same order. Instead, I would suggest poplutaing a combo box with the IDs and letting the user select.

 

Also, if you're going to actually use this, I would suggest reading the relevant pages at the MSDN, as I wouldn't be surprised if there are ways to get this wrong which you won't see until the code runs on a computer in another country, so you would want to understand exactly how to use it correctly.


___________________
Try to take over the world!
0 Kudos
Message 8 of 12
(2,226 Views)

And in addition to what tst said, if you intend to run this code multiple times during the life time of your application it would be a good idea to actually Close every single .Net reference that you get in that diagram after use. Otherwise you will potentially create memory hogs (not leaks since LabVIEW knows about the memory allocations but you didn't tell it that those references are not needed anymore and it will hold onto them until the application terminates).

Rolf Kalbermatter
Averna BV
LabVIEW ArchitectLabVIEW ChampionLabVIEW Instructor
0 Kudos
Message 9 of 12
(2,188 Views)

Yeap, I am quite consicious about closing references, although for a quick demo I wasnt bother too much.

 

Thanks for the contribution of both of you.

0 Kudos
Message 10 of 12
(2,183 Views)