Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating epoch time in Automation rule?

Ben Hart
Contributor
May 6, 2024

I'm wanting to create a manual action that will perform a web request. The payload of this request defines a 'startDateTime' and an 'endDateTime', both of which are represented in epoch -> milliseconds.

The action should provide a value of 1 hour by default.. I am thinking about a second option for a custom time range but that's not as important to me as this 1 hour span is.

 

So my idea was, create a variable for {{now}} except it complains when I try to save {{now}} under a Create Variable step.

Also I got errors trying to set a smart value with math functions..

 

Anyone out there happen to do something like this?

3 answers

2 accepted

3 votes
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 6, 2024

Hi @Ben Hart 

I recall the easiest way to do this is:

{{#now}}format="toMillis"{{/}}

That will return the UNIX timestamp to milliseconds.

If you need some adjustments at the same time, such as incrementing a field, this would work:

{{#issue.Start date}}func=plusMonths(1), format="toMillis"{{/}}

 

FYI...I also did the brute-force calculation before I learned this approach, building the math expression for milliseconds since the start of 1970, and confirmed the results were the same.

 

Kind regards,
Bill

Ben Hart
Contributor
May 6, 2024

Works fine! And it's shorter than my route! Thanks man!

Like • Bill Sheboy likes this
0 votes
Answer accepted
Ben Hart
Contributor
May 6, 2024

This is my first experiment:

A webcall to https://currentmillis.com/time/minutes-since-unix-epoch.php

Create var: epochMinutes {{webResponse.body}}

Add audit log: {{webResponse.body}}

Create var: epochMilli {{#=}}{{epochMinutes}} * 60000{{/}}

Add audit log: epochMilli

 

Now in the audit log, the log step for epochMilli is not displayed for some reason. However if I add a Then add comment, and define the comment with the same math syntax it does get added.

Ben Hart
Contributor
May 6, 2024

Ok next step.. another variable adding 3.6M seconds to {{epochMilli}}. This value, even though shortened to 1.71501054E12 actually works!

 

So with vars {{epochMilli}} and {{epochOneHour}} I can do what I was wanting to do.. which was an Action to send a device SDT to LogicMonitor for 1 hour.

0 votes
Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2024

@Bill Sheboy   is there a way to do this in reverse?  I have the Unix timestamp coming in from a webhook in milliseconds and want to display the date in an issue.

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2024

Hi @Ste404 

One way to do this would be using knowledge about the "start of epoch time", create a variable with that value, and then add the milliseconds to it:

  • action: create variable
    • name: varStartOfTime
    • smart   value: {{now.withYear(1970).withDayOfYear(1).toDateTimeAtStartOfDay}}
  • ...something to get your Unix timestamp in milliseconds: let's assume it is in a variable named varMillis
  • the date / time for that would be: {{varStartOfTime.toDate.plusMillis(varMillis.asNumber)}}

Kind of a hack although I expect it should work.

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
atlassian, confluence, loom, atlassian intelligence, ai notes, ai-powered meeting notes, atlassian community events, ace, confluence ai, loom ai integration, ai note-taking, atlassian ai features, team '25, atlassian live learning, confluence automation

Unlock AI-powered meeting notes: Join our live learning session! 📹

Did you catch the news at Team ‘25? With Loom, Confluence, Atlassian Intelligence, & even Jira 👀, you won’t have to worry about taking meeting notes again… unless you want to. Join us to explore the beta & discover a new way to boost meeting productivity.

Register today!
AUG Leaders

Atlassian Community Events