Open In App

JavaScript Converting milliseconds to date

To Convert milliseconds to date You can achieve this using the Date object, In this article we will see how to Convert milliseconds to date.

Approach

Example 1: This example first gets the milliseconds of the current date and time, Then uses that value to get the date by Date() method






let time = new Date().getTime();
function GFG_Fun() {
    let date = new Date(time);
    console.log("Milliseconds = "+ date.toString());
}
GFG_Fun()

Output
Milliseconds = Wed Dec 20 2023 07:22:36 GMT+0000 (Coordinated Universal Time)

Example 2: This example first gets the random milliseconds(1578567991011 ms), Then uses that value to get the date by Date() method.






let milliseconds = 1578567991011;
function GFG_Fun() {
    let date = new Date(milliseconds);
    console.log("Milliseconds = " + date.toString());
}
GFG_Fun()

Output
Milliseconds = Thu Jan 09 2020 11:06:31 GMT+0000 (Coordinated Universal Time)

JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.

Article Tags :