Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript Todays date [duplicate]

Possible Duplicate:
How to get current date in JavaScript

I need to get todays date in the format yyyymmdd using JavaScript.

I've used the following code:

var d = new Date();
d.getFullYear()+ '' +((d.getMonth()+1)) + '' + d.getDate();

But the month and date are returned in single digits, does someone know how to do this?

like image 254
van Avatar asked Aug 29 '26 04:08

van


1 Answers

        var d = new Date();
        var df = d.getFullYear()
            + ('0' + String(d.getMonth()+1)).substr(-2)
            + ('0' + String(d.getDate())).substr(-2);
        alert(df);
like image 148
Michael Besteck Avatar answered Aug 31 '26 18:08

Michael Besteck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!