How to get current date and time in JavaScript

4 Answers

0 votes
var today = new Date();

document.write(today);


  
/*
run:
  
Wed Sep 18 2019 20:35:33 GMT+0300 (Israel Daylight Time) 
     
*/

 



answered Sep 18, 2019 by avibootz
0 votes
var today = new Date();
var dt = today.getFullYear() + '.' + (today.getMonth() + 1) + '.' + today.getDate();
 
document.write(dt);
 
 
   
/*
run:
   
2019.9.18 
      
*/

 



answered Sep 18, 2019 by avibootz
0 votes
var today = new Date();
var tm = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
 
document.write(tm);
 
 
   
/*
run:
   
20:48:17
      
*/

 



answered Sep 18, 2019 by avibootz
0 votes
var today = new Date();
var dt = today.getFullYear() + '.' + (today.getMonth() + 1) + '.' + today.getDate();
var tm = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
 
document.write(dt + " " + tm);
 
 
   
/*
run:
   
2019.9.18 20:49:31 
      
*/

 



answered Sep 18, 2019 by avibootz
...