How to convert unix epoch timestamp to DateTime

Hongman Kim
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 27, 2020

I'm using a Web request to get data from another service.

The Json response look like this.

"result": [
  "lastclock": "1601240174",
  "lastvalue": "69.2"
   "lastclock": "1601240174",
   "lastvalue": "50.1"

lastclock is the timestamp in unix epoch time, and I like to convert this to Jira DateTime object. I tried "toDate" but did not work.

Using the Log Action, the following give no output.


Maybe I need to provide the time format to "toDate" function?  But I'm not sure what the format should be. 

What would be the best way to convert unix epoch seconds to Jira date time using the Automation for Jira plug-in?

1 answer

5 votes
Italo _Modus Create_ October 1, 2021

Hi @Hongman Kim ,


We had the same challenge today and we were able to do a workaround by going back to 1970 and summing the milliseconds to the date you are looking for.


First, you create a variable with the 01/01/1970 date


1. Create variable

Variable name: epochDate

Smart value: 01/01/1970


Then you can use this variable to generate your dates using Epoch, in your case lastclock is returning Seconds, so you should be able to use something like below.


2. Log action



In our case we are used Millis so it's 



You can then use this to set JIRA Fields in the Automation :D 


Hope this helps!

Dane Kantner October 25, 2021

jira smart values do not allow to use plusSeconds with another smart value though, it seems, so this might be fruitless in most cases... e.g., you can do {{epochDate.toDate("dd/MM/yyyy").plusSeconds(1601240174)}}  but not a dynamic value for 1601240174 within the plusSeconds() (it seems?)

Like Italo _Modus Create_ likes this
Italo _Modus Create_ October 26, 2021

@Dane Kantner , we were able to use a dynamic value in the function using a second variable, we used millis but I think this might work with Seconds.

1. Create a variable

Variable name: endDataInMillis

Smart value: {{yourSmartValueHere}}


In your action you can use the following:



It only worked when casting the variable to number using asNumber function.

Like # people like this
Dane Kantner October 26, 2021

thank you so much for the .asNumber, I had been trying to find if there was a need to cast the string->int for this purpose but couldn't find that ... that actually fixed it. In my case I'm actually diffing between a previously opened issue and newly opened and doing some math on that difference, so I'm adding the plusSeconds to the new create date vs 1970... I just needed the smartvariablename.asNumber for it to add the plusSeconds to that create date.


The other problem I was having with calculating that date itself was I was trying to use the lookupIssue variable to retrieve the resolutionDate field, and that isn't returned with the lookupIssues smart var. Instead I had to do a lookup for the issue I wanted, and then use a branch to do JQL search of that found lookupIssue, and that does the branch loop on that issue 2 where I can set a smart variable to capture the resolutionDate. Then outside of the branch lookup, I can use that smart var to calculate whatever and set fields in the original issue 1.

Like Italo _Modus Create_ likes this

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events