cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to convert time stamps in an array to dates

Jake_pm
New Contributor II

How to you convert a timestamp to datetime format? The API that I call uses a timestamp and I need to convert those to mm/dd/yyyy.

hereโ€™s an example of the timestamp response.
timestamp

1 ACCEPTED SOLUTION

j_angelevski
Contributor III

Hi @Jake_pm ,

You can use the Date.parse() function to convert the timestamp into datetime format ( MM/dd/yyyy ).
You can iterate over the array by using .map(), for example:

$time_stamp.map(val => Date.parse(val).toLocaleDateTimeString({format: "MM/dd/yyyy"}) )

Input:

[
   {
      "time_stamp":[
         1675202216000,
         1675195016011
      ]
   }
]

Output:

[
   {
      "time_stamp":[
         "01/31/2023",
         "01/31/2023"
      ]
   }
]

View solution in original post

2 REPLIES 2

j_angelevski
Contributor III

Hi @Jake_pm ,

You can use the Date.parse() function to convert the timestamp into datetime format ( MM/dd/yyyy ).
You can iterate over the array by using .map(), for example:

$time_stamp.map(val => Date.parse(val).toLocaleDateTimeString({format: "MM/dd/yyyy"}) )

Input:

[
   {
      "time_stamp":[
         1675202216000,
         1675195016011
      ]
   }
]

Output:

[
   {
      "time_stamp":[
         "01/31/2023",
         "01/31/2023"
      ]
   }
]

Jake_pm
New Contributor II

Thank you for the quick response @j.angelevski !
your solution worked perfectly!