UTC to localtime conversion problem

Hello!
I am beginner with Ignition and I have a such problem: I got a big number from PLC, like 12918834598000 which is UTC time and i need to convert it to the human readable format.
I have defined a expression for the label like runScript(“app.util.UTC_to_LocalTime()”)
And also a function in the app.util package, called UTC_to_LocalTime
def UTC_to_LocalTime():
import time
print “Converting value ‘%d’ to ‘%s’%” % (1233445678, localtime(1233445678))
return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(epoch))

It is just for testing, since i always have error:
java.lang.Exception: Error executing expression binding on

Well, there is something wrong with the binding. Maybe toString method could be used somewhere? I just need to get to work the UTC to Local Time translation.

Thank you!!!

Hi,

If you can get more details about the error, I suspect it’s not a problem with the binding, but instead is reporting an error that occurred in the actual script. You should also be able to go to Help>Diagnostics in the Designer, and see the error in the console.

However, you may not need to do all of this. Something like the following should work in the expression:

toDate(toLong(1233445678)*1000)

Basically, the toDate() can take a long, which is “the specified number of milliseconds since the standard base time known as “the epoch”, namely January 1, 1970, 00:00:00 GMT.” (<- according to Java’s docs). You might need to adjust your value a bit, depending on the system used. That value, which I took from your example, is from 2009… which I guess could be right, but doesn’t seem like it.

Regards,

Worked like a charm!
Thank you so much!
A little bit smarter now.