Convert milliseconds to new date in js
You can use the Date
object in JavaScript to convert milliseconds to a new date. Here's an example:
const milliseconds = 123456789; // example value
const date = new Date(milliseconds);
console.log(date); // Output: Fri Feb 13 2026 14:29:07 GMT-0500 (Eastern Standard Time)
The Date
constructor takes a single argument, which is the number of milliseconds since the Unix epoch (January 1, 1970, 00:00:00 UTC). In this example, we pass in the milliseconds
value, and the Date
object is created with that value.
If you want to format the date in a specific way, you can use the toLocaleString()
method or create a custom format using template literals:
const milliseconds = 123456789;
const date = new Date(milliseconds);
const formattedDate = date.toLocaleString(); // Output: February 13, 2026 2:29:07 PM
// or
const formattedDate = `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
// Output: 2/13/2026 2:29:07 PM
Note that the toLocaleString()
method returns a string representation of the date in the user's locale, so the format may vary depending on the user's settings. If you need a specific format, you can use the toLocaleDateString()
and toLocaleTimeString()
methods separately.