Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to format a date and time in JavaScript

2 Answers

0 votes
const dt = new Date('November 1, 2019 10:33:01');

document.write(dt + "<br /><br />");

    
date = new Date()

document.write(date.toString() + "<br />");
document.write(date.toTimeString() + "<br />");
document.write(date.toDateString() + "<br />");
document.write(date.toUTCString() + "<br />");
document.write(date.toISOString() + "<br />");
document.write(date.toLocaleString() + "<br />");
document.write(date.toLocaleTimeString() + "<br />");



/*
run:
      
Fri Nov 01 2019 10:33:01 GMT+0200 (Israel Standard Time)

Mon Nov 04 2019 11:34:13 GMT+0200 (Israel Standard Time)
11:34:13 GMT+0200 (Israel Standard Time)
Mon Nov 04 2019
Mon, 04 Nov 2019 09:34:13 GMT
2019-11-04T09:34:13.118Z
04/11/2019, 11:34:13
11:34:13
    
*/

 



answered Nov 4, 2019 by avibootz
edited Nov 4, 2019 by avibootz
0 votes
date = new Date()

document.write(date.getDate() + "<br />");
document.write(date.getDay() + "<br />");
document.write(date.getMonth() + "<br />");
document.write(date.getFullYear() + "<br /><br />");

document.write(date.getHours() + "<br />");
document.write(date.getMinutes() + "<br />");
document.write(date.getSeconds() + "<br />");
document.write(date.getMilliseconds() + "<br />");
document.write(date.getTime() + "<br />");



/*
run:
      
4
1
10
2019

11
38
22
134
1572860302134
    
*/

 



answered Nov 4, 2019 by avibootz

Related questions

1 answer 116 views
1 answer 123 views
3 answers 194 views
1 answer 150 views
1 answer 89 views
1 answer 147 views
...