views:

262

answers:

4

alert(dateObj) gives Wed Dec 30 2009 00:00:00 GMT+0800

How to get date in format 2009/12/30?

+2  A: 

Nice formatting add-in: http://blog.stevenlevithan.com/archives/date-time-format.

With that you could write:

var now = new Date();
now.format("yyyy/mm/dd");
The MYYN
A: 

Use the Date get methods.

http://www.tizag.com/javascriptT/javascriptdate.php

http://www.htmlgoodies.com/beyond/javascript/article.php/3470841

var dateobj= new Date() 
var month = dateobj.getMonth() 
var day = dateobj.getDate()
var year = dateobj.getFullYear()
document.write(month + "/" + day + "/" + year)
Aseem Gautam
Months on JavaScript Date objects are zero-indexed. Be sure to add 1 to it, else December gets to be November; November gets to be October and so forth
roosteronacid
+5  A: 
rahul
+1 for month index reminder
Rubens Farias
+4  A: 
var month = dateObj.getUTCMonth();
var day = dateObj.getUTCDay();
var year = dateObj.getUTCFullYear();

newdate = year + "/" + month + "/" + day;

or you can set new date and give the above values

peacmaker
Just remember: January=0, February=1, and so on.
Rubens Farias
What's the difference between `getMonth` and `getUTCMonth`?
UTC will return universal time.if you want local time use getMonth
peacmaker
`getUTCDay()` should be replaced by `getUTCDate()`, since day is the number of the day in week (0-6) and date is the number of the day in month (1-31).
Grzegorz Oledzki