PDA

View Full Version : reformat javascript date object?



kenw232
12 Jan 2011, 04:43 AM
Hi I have a jquery calendar I'm using. It returns the date in javascript. The variable/object looks like this:
"Fri Jan 14 2011 05:42:56 GMT-0500 (Eastern Standard Time)"

I would like to take that and reformat it to yyyy/mm/dd. How can I do that?

resdog
13 Jan 2011, 10:59 AM
assuming the variable that holds the date object is "currentTime":



var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var formattedDate = year + "/" + month + "/" + day;


Then you can use the variable "formattedDate" to display wherever you want.