Convert 63788415353 (possibly in milliseconds) to "hour:minute:seconds" format using Arcade

549
3
06-13-2022 01:36 AM
aadejobi
New Contributor

How do I convert 63788415353 (possibly in milliseconds) to "hour:minute:seconds" format using Arcade

0 Kudos
3 Replies
JohannesLindner
MVP Frequent Contributor

Hi, welcome to the ESRI community!

I'm not sure what you mean by "possibly in milliseconds", could you elaborate on that?

 

In case you mean the UNIX epoch (milliseconds since 1970-01-01 00:00:00), you can do it by converting the number to a Date and then formatting that Date with the Text function:

 

var x = 63788415353
var x_date = Date(x)
var x_date_formatted = Text(x_date, "HH:mm:ss")

Console(`x: ${x}`)
Console(`x as Date: ${x_date}`)
Console(`Date(x) as HH:mm:ss : ${x_date_formatted}`)

 

x: 63788415353
x as Date: 1972-01-09T08:00:15.353+01:00
Date(x) as HH:mm:ss : 08:00:15
 

 


Have a great day!
Johannes
0 Kudos
aadejobi
New Contributor

Hi Johannes,

Thanks for the solution offered. I really appreciate it. The result i'm expecting is 20:15:53. When i used the expression below in ArcMAP, result i got was 20:15:53 but i don't know how to replicate the same result in Pro using arcade.

(datetime.datetime(1900,1,1) + datetime.timedelta(microseconds = (esri__measure * 10000000) /10)).strftime("%H:%M:%S")

 

0 Kudos
JohannesLindner
MVP Frequent Contributor

OK, you could do that with the DateAdd function:

 

var esri__measure = 63788415353
var as_date = DateAdd(Date("1900-01-01"), esri__measure * 10000000 / 10, "microseconds")
var only_time = Text(as_date, "HH:mm:ss")

Console(`esri__measure: ${esri__measure}`)
Console(`esri__measure as Date: ${as_date}`)
Console(`esri__measure as HH:mm:ss : ${only_time}`)

 

esri__measure: 63788415353
esri__measure as Date: null
esri__measure as HH:mm:ss : Invalid DateTime

 

But, as you see, Arcade can't handle your input. If you run your code in python, but return the whole date, you get a date in the year 3921, which is probably too big for Arcade. Are you sure about your Python code?

esri__measure = 63788415353
datetime.datetime(1900,1,1) + datetime.timedelta(microseconds = (esri__measure * 10000000) /10)).isoformat()
#'3921-05-17T20:15:53'

 


Have a great day!
Johannes
0 Kudos