# UTC to localtime conversion problem

**URL:** <https://forum.inductiveautomation.com/t/utc-to-localtime-conversion-problem/4070>\
**Category:** Ignition\
**Created:** [February 27, 2012, 3:25pm UTC](https://forum.inductiveautomation.com/t/utc-to-localtime-conversion-problem/4070 "2012-02-27T15:25:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gljuk](https://avatars.discourse-cdn.com/v4/letter/g/90ced4/32.png) [@gljuk](https://forum.inductiveautomation.com/u/gljuk)\
**Post date:** [February 27, 2012, 3:25pm UTC](https://forum.inductiveautomation.com/t/utc-to-localtime-conversion-problem/4070/1 "2012-02-27T15:25:26Z")

</div>

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!!!

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [February 27, 2012, 4:26pm UTC](https://forum.inductiveautomation.com/t/utc-to-localtime-conversion-problem/4070/2 "2012-02-27T16:26:51Z")

</div>

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:

```auto
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,

---

<div class="post-metadata">

**Author:** ![gljuk](https://avatars.discourse-cdn.com/v4/letter/g/90ced4/32.png) [@gljuk](https://forum.inductiveautomation.com/u/gljuk)\
**Post date:** [February 28, 2012, 6:55am UTC](https://forum.inductiveautomation.com/t/utc-to-localtime-conversion-problem/4070/3 "2012-02-28T06:55:23Z")

</div>

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