How do I get the current date in JavaScript

0 votes
How do I get the current date in JavaScript?
Feb 18 in Java by Rahul
• 9,680 points
67 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 by Aditya
• 7,660 points

Related Questions In Java

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,190 points
1,366 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
25,835 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,800 points
281 views
0 votes
1 answer

How to get the current date/time in Java?

It depends on what form of date/time ...READ MORE

answered Dec 30, 2020 in Java by Gitika
• 65,890 points
335 views
0 votes
0 answers
0 votes
0 answers

How do I format a date in JavaScript?

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

Sep 21 in Java by Nicholas
• 7,120 points
49 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 in Java by Aditya
• 7,660 points
83 views
0 votes
1 answer

Compare two dates with JavaScript

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

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

How do I redirect with JavaScript?

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

answered Feb 16 in Java by Aditya
• 7,660 points
65 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