alert(dateObj)
gives Wed Dec 30 2009 00:00:00 GMT+0800
How to get date in format 2009/12/30
?
The Date object methods getDate() , getMonth() , and getFullYear() can be used to retrieve day, month, and full year from a date object in JavaScript. Note that the getDate() , getMonth() , and getFullYear() methods return the date and time in the local time zone of the computer where the code is running.
To get the day of the month, use the getDate() method. JavaScript date getDate() method returns the day of the month for the specified date according to local time. The value returned by getDate() is an integer between 1 and 31.
The getYear() method is used to get the year of a given date according to local time. The getYear() method returns the year minus 1900; thus: * For years above 2000, the value returned by getYear() is 100 or greater. For example, if the year is 2009, getYear() returns 109.
var dateObj = new Date(); var month = dateObj.getUTCMonth() + 1; //months from 1-12 var day = dateObj.getUTCDate(); var year = dateObj.getUTCFullYear(); newdate = year + "/" + month + "/" + day;
or you can set new date and give the above values
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With