Example Code

Convert a time stamp from UTC to Locale and back

Code and Documents

Attachment

Overview

A sample VI for converting a Time Stamp from Locale time (local computer time zone time) to Coordinated Universal Time (UTC) and vice versa

 

 

Description

Use this VI example to understand methods for inter-changing timestamps between Locale and UTC.
Note: The Time Stamp format does not contain locale information and must be interpreted as UTC or Locale as appropriate.
Note: Daylight Savings Time (DST) is automatically considered as a part of the Local settings
Note: Changes to the Windows Time Zone settings will only be recognized by LabVIEW following a restart.

 

 

Steps to Complete

1. Launch the VI "Local-UTC Time Conversion_LV2012_NI Verified"

2. Choose the local time and time in UTC that you want to convert
3. Run the VI

 

 

Additional Information or References

Block Diagram

BD.PNG

 

Front Panel

FP.PNG

 

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

Thoric (CLA, CLED, CTD and LabVIEW Champion)


Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
987654321
Member
Member
on

Can we get a 8.6 or older version for the old guyes

jmsantos
Member
Member
on

I am sorry but I am working with 7.1 version. Can you get al block picture from the vi.

Thank you

Thoric
Trusted Enthusiast Trusted Enthusiast
Trusted Enthusiast
on

I've managed to save for 8.0, but I currently don't have immediate access to LV8 to be able to create a 7.1 version.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


987654321
Member
Member
on

Thank you sir ! !

gdul
Member
Member
on

The format string in Scan From String is incorrect. The function will return an error if the time difference is negative. Replacing with %3d:%2d:%2d works fine

Thank you

Thoric
Trusted Enthusiast Trusted Enthusiast
Trusted Enthusiast
on

gdul,

Thanks for spotting that. To be accurate, one should avoid the use of width specifiers and simply use: "%d:%d:%d", this will capture three integers of any width and hence therefore numbers with or without a preceding sign character.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


StephenGerads
Member
Member
on

Warning! This only works for converting timestamps with the same DST status as the current time. "Difference between UTC and locale" and "Locale time shift date time record" are correct only if the "Locale Time Stamp" input timestamp has the same DST status as the current time.

Fix: the "Locale >> UTC" section should have a True into the Seconds to DateTime function and it not subtract anything from the time record.

Thoric
Trusted Enthusiast Trusted Enthusiast
Trusted Enthusiast
on

Since developing this over two years ago I've encountered a couple of scenarios whereby these functions are incorrect. I can't recall the specific scenarios but I suspect that which you've identified StephenGerads is one of them. Time conversion from one time zone/DST period to another is a tricky business!

Thoric (CLA, CLED, CTD and LabVIEW Champion)


ScotiMSD22
Member
Member
on

Get Locale Time BD.pngThis method seems to work well to get a locale timestamp