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
• 8,980 points
21 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,280 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,170 points
1,044 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,122 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,680 points
217 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,850 points
139 views
0 votes
0 answers
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,280 points
21 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
• 8,980 points
18 views
0 votes
1 answer

Format JavaScript date as yyyy-mm-dd

You could try using the following lines ...READ MORE

answered Feb 23 in Java-Script by Aditya
• 7,280 points
62 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,280 points
24 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP