From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Programmatically Set Time Zone on RT Controller in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

    Driver

  • Other

Code and Documents

Attachment

Overview
Demonstrates how to set time zone on Real-Time (RT) controller using Set Time VI.

 

Description

This example computes the difference between current time and UTC time and then builds time string in Etc/GMT+-X format. The time zone is set to target devices using Set Time VI.

 

Requirements

LabVIEW 2012 Full edition (or compatible)

NI System Configuration driver package

 

Steps to Implement or Execute Code

  1. Configure the RT Target session
  2. Set your time zone. You can review a list of time zone strings on the Date and Time Gateway website
  3. Run the program
  4. The time zone will be in the form of Etc/GMT+-X, where X represents the offset from GMT

 

Additional Information or Resources

VI Block Diagram

 

BD.png

 

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

Rob B
FlexRIO Product Manager

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

Comments
fps
Member
Member
on

This VI has helped a great deal in attempting to keep the time sync'd between a cRIO and a Windows machine. However, I did notice that the "Changes Require Restart" output is set after running the VI. Do I really have to restart my cRIO after running this VI?

Example_Scrubber_Kean
Member
Member
on

Hi fps,

 

Yes. If "changes require restart" returns True, run the Restart VI. Please find details at LabVIEW Help.

Ajay_MV
Active Participant
Active Participant
on

I think there is a potential bug in this block diagram.   Wiring False constant to terminal to UTC? of Seconds to Date/Time not and True to is UTC? Date/Time to Seconds node gives unexpected time output.  Instead, using using one more Seconds to Date/Time as below fixes the issue.  I tested for IST and you can see the difference.

 

Screenshot 21-08-2017 195100.pngBD_Fix.png

--
Ajay MV


a.dam
Member
Member
on

Hi,

 

I cannot figure out what the code should look like when the RT Controller should be set to a time zone deviating from UTC buy more than an integer hour. E.g. Katmandu is at GMT+5:45 and Tehran at GMT+3:30. It should be possible since I can find the alternatives in the time settings via NI MAX. For Katmandu I have tried all formats I could imagine including 'Etc/GMT'+.... '-0545', '-545', '5,45', '-5.45', '-5:45', '-5.75 ', '-5,75', '-0575', '-575'. All rendered an error message and no changed time zone. Anyone have any idea or possibly the answer? Would be very much appreciated.

a.dam
Member
Member
on

I solved my problem using a ring control mapping odd time zone's strings (taken from twiki.org/) to their UTC offsets. A bit ugly but it works. Tried for all odd time zones during normal and daylight saving time. Does not work when automatic DST is off at the host computer and on at the RT controller.

 

SetTimeZoneRT [all time zones + DST]SetTimeZoneRT [all time zones + DST]