LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Format relative time string with options

Solved!
Go to solution

I am looking for a way to format relative time in seconds to a string that shows hours, minutes, seconds with these options.

Option 1: show/hide milliseconds

Option 2: show Days, Hours, Minutes, Seconds with option 1

 

I have tired both Format into string with the t format string. This is almost perfect except it always shows milliseconds.

 

I have tried Format Data/Time string but is won't show milliseconds, it wont show hours over 23, and always adds one day when I use %#d 

 

It there any way to get the format I want with the options I am after?

 

ts3apture.PNG

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 1 of 4
(210 Views)
Solution
Accepted by topic author RTSLVU

I'm a little confused at what you want. Could you give an example?

 

I think your issue is that "Format Date/Time String" doesn't appear to support relative time. It interprets your number as the number of seconds since the epoch.

 

That said, Format into String will do what you want. You just need to modify your code a bit, and use the "extra" characters inside <> before your t.

 

To get seconds by itself, use %<%S>t.

To get milliseconds, use  %<%S%.3u>t.

To get hours:minutes:whole seconds, use %<%H:%M:%S>t.

To get hours:minutes:seconds.milliseconds, use %<%H:%M:%S%.3u>t.

To add days, add a %D before the %H.

 

timestamp4.png

 

(You can use %t with number of digits specifiers too- for example, %.3t should show milliseconds, but it didn't give me exactly what I expected with whole days.)

Message 2 of 4
(193 Views)

You have shown me what I needed to see. 

 

Basically a countdown timer is a very common request in my programs. I am trying to make a universal vi with the options I need that I can use everywhere.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 4
(176 Views)

Glad it's working. (FWIW, I just noticed a copy/paste error in my code... one of the ones that isn't supposed to show milliseconds does indeed show milliseconds. Just delete the ".3u" from the format code.)

0 Kudos
Message 4 of 4
(170 Views)