How do I get the current date in JavaScript

0 votes
How do I get the current date in JavaScript?
Feb 18, 2022 in Java by Rahul
• 9,680 points
583 views

1 answer to this question.

0 votes

To ensure that you get the current date in JavaScript, start with using new Date() to generate a new Date object containing the current date and time.

var today = new Date(); 
var dd = String(today.getDate()).padStart(2, '0'); 
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! 
var yyyy = today.getFullYear(); 

today = mm + '/' + dd + '/' + yyyy; 
document.write(today);

 

This will give you today's date in the format of mm/dd/yyyy.

Simply change today = mm +'/'+ dd +'/'+ yyyy; to whatever format you wish.
answered Feb 18, 2022 by Aditya
• 7,680 points

Related Questions In Java

0 votes
0 answers

How do I get the current time only in JavaScript

In JavaScript, how can I retrieve the ...READ MORE

Dec 9, 2022 in Java by Nicholas
• 7,760 points
561 views
0 votes
2 answers

How do I get the current date and time using Java?

If you require a time stamp in ...READ MORE

answered Aug 23, 2019 in Java by Sirajul
• 59,230 points
2,932 views
0 votes
1 answer

How can I get the current date and time in UTC or GMT in Java?

This definitely returns UTC time: as String ...READ MORE

answered Jun 7, 2018 in Java by Rishabh
• 3,620 points
27,613 views
0 votes
1 answer

How can I get the current stack trace in Java?

Hello @kartik, Try this: Thread.currentThread().getStackTrace(); is fine if you don't ...READ MORE

answered Jul 28, 2020 in Java by Niroj
• 82,840 points
1,032 views
0 votes
0 answers

How do I format a date in JavaScript?

May 7, 2022 in Java-Script by narikkadan
• 63,600 points
464 views
0 votes
0 answers

How do I format a date in JavaScript?

How can I convert a Date object ...READ MORE

Sep 21, 2022 in Java by Nicholas
• 7,760 points
459 views
0 votes
1 answer

Parsing a string to a date in JavaScript

The best string format for string parsing ...READ MORE

answered Feb 18, 2022 in Java by Aditya
• 7,680 points
639 views
0 votes
1 answer

Compare two dates with JavaScript

 The Date object will do what you ...READ MORE

answered Feb 18, 2022 in Java by Rahul
• 9,680 points
730 views
0 votes
1 answer

How do I resolve the "java.net.BindException: Address already in use: JVM_Bind" error?

If you are aware about what port ...READ MORE

answered Feb 22, 2022 in Java by Aditya
• 7,680 points
5,109 views
0 votes
1 answer

How do I redirect with JavaScript?

To redirect to another page by Using ...READ MORE

answered Feb 16, 2022 in Java by Aditya
• 7,680 points
537 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP