LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Format timestring - how to adapt timezone %z and separator for seconds?

Hello together,

 

with the format specifier %z I am able to add the correct time zone indicator. However, it has the form hh:mm:ss. How can I limit it to hh:mm? By default, only a "-" is displayed in front of the time zone indicator. How do I make it write a "+" if necessary as well?

 

Is it possible to change the "," into "." after seconds?

 

Actual format string:

2019-10-28_10h03_01.png

 

Timestring result:

2019-10-28T10:02:06,79501:00:00

 

Desired format (timezone indicator only hh:mm and "." instead of "," after seconds)

2019-10-28T10:02:06.795+01:00 or 2019-10-28T10:02:06.795-01:00

 

Thank you for your help and tips,
Michael

 

 

0 Kudos
Message 1 of 8
(3,513 Views)

I think you get a coma (,) because of the settings of your OS (Windows presumably), is your OS language french?

I know that when Windows' language is french, coma is the default decimal separator, you can either change that in Windows, but I woudn't recommend it or force LabVIEW to ignore the OS default decimal separator and use the dot (.)

 

To do that, open you labVIEW settings Tools>> Options... >> make sure the box is unticked

Annotation 2019-10-28 112908.png

You'll need to relaunch LabVIEW.

 

Also, if you ship you code as an EXE, make sure the INI file next to your EXE contains this "useLocaleDecimalPt=False"

It will nake sure your EXE ignores the OS default adn use the dot (.)

 

Hope this helps

 


We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

0 Kudos
Message 2 of 8
(3,487 Views)

Enclosed is my solution. If there is a more elegant way I look forward to receiving hints. Thank you.

2019-10-28_13h52_09.png

0 Kudos
Message 3 of 8
(3,458 Views)

You can force the decimal separator to be a comma (not a coma!) by putting "%,;" in your format, like this:

"%.;%Y-%m-%dT%H:%M:%S%.3u%z".

I couldn't get rid of the seconds in the timezone.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 8
(3,428 Views)

ts.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 5 of 8
(3,423 Views)

I'm not in a "positive" time zone so I haven't been able to validate it but I think using "Format Into String" with the following time format will force the "+" sign to be displayed %+<%z>T.

 

The resulting code would be as follow (using Paul method to remove the trailing :00).

 

Ben64

 

Format DateTime.png

Message 6 of 8
(3,404 Views)

I am in a positive time zone, so I can validate it 🙂

Example_VI.png

 

As a side point, changing the system time zone also allows checking this:

Example_VI.png

although I had to close LabVIEW after changing it... (maybe just waiting a bit longer would have worked)


GCentral
0 Kudos
Message 7 of 8
(3,389 Views)

@cbutcher wrote:

 

although I had to close LabVIEW after changing it... (maybe just waiting a bit longer would have worked)


My experience is that LabVIEW only checks the timezone when it is first opened.  So changing timezones requires a stop and restart of the LabVIEW environment.

0 Kudos
Message 8 of 8
(3,381 Views)