Parse Time stamp


(Morgan) #1

Sorry for the simple question… How do i parse a timestamp in JSON to a display of a nice date time? I’m not familiar with it.

The timestamp would be

1455661738

2/16/2016 02:05 PM

or something like that.


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #2

It’s in Unix “Epoch” format… Lots of available methods to convert, many provided on this helpful site:

http://www.epochconverter.com/


(Morgan) #3

What would the code be in a groovy app?


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #4

I believe that most of the Java methods will work.

See the lower portion of the linked page…


(Morgan) #5

I’m getting an

Error: java.lang.IllegalArgumentException: Cannot format given Object as a Date

Do i need to convert it to a Int or something?


(Morgan) #6

Yeah, i used the java methods and tried… no luck. When i put the value in the epoch converter it shows the right date time. But nothing inside of the groovy app.


(Mike Maxwell) #7

def timeString = new Date(unixTS+ location.timeZone.rawOffset ).format(“yyyy-MM-dd HH:mm”)
That would convert from UTC to your hubs current time zone.
If you just want the conversion, drop the location offset


(Morgan) #8

Thanks Mike, that was what I need. I appreciate it.