How to get the current date and time in Node.js

5 Answers

0 votes
const moment = require('moment'); // Install moment before (npm i moment)
   
console.log(`${moment().format()}`);
 
  
  
/*
run:
   
2020-03-18T11:40:47+02:00

*/

 



answered Mar 18, 2020 by avibootz
0 votes
const dt = new Date();

console.log(dt.getFullYear() + "-" + dt.getMonth() + "-" + dt.getDate());

console.log(dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds());

  
  
/*
run:
   
2020-2-18
12:21:30

*/

 



answered Mar 18, 2020 by avibootz
0 votes
const moment = require('moment'); // Install moment before (npm i moment)
    
console.log(`${moment().date()}-${moment().month()}-${moment().year()}`);
console.log(`${moment().hour()}:${moment().minute()}-${moment().second()}`);

  
/*
run:
   
18-2-2020
12:26-54

*/

 



answered Mar 18, 2020 by avibootz
0 votes
console.log(new Date());
 
   
     
     
/*
run:
     
2022-02-27T10:50:09.127Z
     
*/

 



answered Feb 27, 2022 by avibootz
0 votes
console.log(new Date().toDateString());
 
   
     
     
/*
run:
     
Sun Feb 27 2022
     
*/

 



answered Feb 27, 2022 by avibootz

Related questions

1 answer 148 views
1 answer 173 views
1 answer 188 views
1 answer 127 views
1 answer 205 views
...