CALCULATION - JS

Java on dates

JDate: Date/time

Don't forget to check the documentation for the JDate Class

JS : Returning a date -17h

//Convert the date in a millisecond timestamp 
const date1 = new Date("2021-01-01 00:00:00").getTime()

//We remove 17 hours to Date1 and put the result in Date2 
                                    //17 * 60 (min) * 60 (sec) * 1000 (millisecond timestamp)
 let date2 = date1 - 17*60*60*1000

JS : Converting a string to a timestamp to get the milliseconds

Solution 1

const timestamp = Date.parse('04 Dec 1995 00:12:00 GMT');
//result : 818035920000

Solution 2

const timestamp2 = new Date("2021-01-01 00:00:00").getTime();
//result : 1609455600000

Was this article helpful?

Powered by Zendesk