Converting millisecond to time read out hh:mm:ss

I’m trying to take the millisecond count down timer from my plc and display it on ignition. Any ideas?

I couldn’t find a pre-made digital clock so I tried scripting and even thought about linking several LED displays to ignition timers with set values and running property bind to trigger to run PLC timer so that it’s not reading it but rather running at the sam time but ran into problems having them stop at 0 and reset when counting down (Sec would need to do this is the time is longer then a min.

Hi! Welcome to the forums!

Answers are usually better if you can provide details. Like what PLC you are using (Some PLC Timers count up, others count down). :thumb_right:

Here’s a jython snippet that converts an arbitrary number of milliseconds to an h:m:s string:

def millis2hms(millis): from java.lang import String from java.util.concurrent import TimeUnit hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))) return hms

Without further details, this is a far as I can reasonably go, but I hope this points you in the right direction.

Also, could the moderators remove the duplicate posts please? :slight_smile:

Unfortunately, trying to delete a post is crashing the forum right now. As soon as we can, we’ll delete the dups.

Sorry about the duplicate post. Site was giving me an error last night and then was sort of unresponsive when I tried again today. I guess it wasn’t as unresponsive after all.

We are using an AB CompactLogix L30ER-NSE.

Thanks for the help so far. I haven’t tried it yet, just wanted to get you the PLC info. Will plug it in now

Just to throw it out there, I was able to do this with an expression, something like this will work

stringFormat("%d:%02d:%02d", toInt(floor({tagvalue}/3600)), toInt(floor(({tagvalue}%3600)/60)), toInt(floor({tagvalue}%60)) )

In Python (7.8.0 and later), you can use system.date.format and system.date.fromMillis for the millisecond to hh:mm:ss without the need to make an additional Python function.

We’re adding the same capability to expressions in 7.9.0.