Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert milliseconds to formatted date in Nodejs

I get a date in Milliseconds like this

1525520235000

and I want to convert it to local time

Sat May 05 2018 17:22:15

How can I accomplish this in NodeJS? Thanks.

like image 404
theanilpaudel Avatar asked Jan 03 '23 10:01

theanilpaudel


2 Answers

may be this helps:

date = new Date(1525520235000);
date.toString();

the result is like:

"Sat May 05 2018 18:37:15 GMT+0700 (SE Asia Standard Time)"

like image 186
Hữu Linh Avatar answered Jan 05 '23 17:01

Hữu Linh


List of all get functions are here : https://www.w3schools.com/js/js_date_methods.asp

var x = 1525520235000;
var mydate = new Date(x);
var month = ["January", "February", "March", "April", "May", "June",
  "July", "August", "September", "October", "November", "December"
][mydate.getMonth()];
var day = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][mydate.getDay()];

console.log('Day: ', day);

console.log('Month: ', month);

console.log('Year: ', mydate.getFullYear());

console.log("Hours: ", mydate.getHours());

console.log("Mitutes: ", mydate.getMinutes());

console.log(mydate.toString("MMMM yyyy"));
like image 45
Saeed Avatar answered Jan 05 '23 17:01

Saeed