How to get the current date and time in JavaScript

3 Answers

0 votes
console.log(new Date());



/*
run:

Wed May 19 2021 10:55:43 GMT+0300 (Israel Daylight Time)

*/

 



answered May 19, 2021 by avibootz
0 votes
console.log(new Date().toDateString());



/*
run:

Wed May 19 2021

*/

 



answered May 19, 2021 by avibootz
0 votes
let dt = new Date();
 
let currentDate = (dt.getMonth() + 1) + '/' + dt.getDate() + '/' + dt.getFullYear() 
let currentTime = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
 
let currentdateTime = currentDate + ' ' + currentTime;
 
console.log(currentdateTime);
     
     
     
     
/*
run:
 
4/15/2024 15:50:32
     
*/

 



answered Apr 15, 2024 by avibootz
...