How to get date and time from timestamp in Node.js

1 Answer

0 votes
const ts = Date.now();

const dt = new Date(ts);

const day = dt.getDate();
const month = dt.getMonth() + 1;
const year = dt.getFullYear();
console.log(year + "-" + month + "-" + day);

const hour = dt.getHours();
const minuts = dt.getMinutes();
const second = dt.getSeconds();
console.log(hour + ":" + minuts + ":" + second);


/*
run:

2020-3-19
10:59:8

*/

 



answered Mar 19, 2020 by avibootz

Related questions

1 answer 119 views
1 answer 153 views
1 answer 143 views
1 answer 162 views
1 answer 127 views
1 answer 148 views
...