how to display a date as 2/25/2007 format in javascript, if i have date object
views:
288answers:
4
+3
A:
This would work:
[date.getMonth() + 1, date.getDay(), date.getFullYear()].join('/')
Reinis I.
2009-10-08 08:55:52
date.getMonth() returns from 0-11 so you need to add 1 to it
TheVillageIdiot
2009-10-08 09:01:55
You're right. I've always been puzzled by that.
Reinis I.
2009-10-08 09:03:19
A:
(date.getMonth() + 1) + "/" + date.getDay() + "/" + date.getFullYear();
Amarghosh
2009-10-08 08:58:31
getYear() - Returns the year, as a two-digit or a three/four-digit number, depending on the browser. Use getFullYear() instead !! (from w3schools.com)
TheVillageIdiot
2009-10-08 09:02:39
+5
A:
function formatDate(a) //pass date object
{
return (a.getMonth() + 1) + "/" + a.getDate() + "/" + a.getFullYear();
}
TheVillageIdiot
2009-10-08 09:01:22
A:
function DateToSting(dte){
return ( ((dte) && (typeof(dte.format)=="function")) ? dte.format("MM/dd/yyyy") : "Not a Date Object" );
}
ASP.net AJAX has a format method protyped to the Date object:
http://stackoverflow.com/questions/414639/asp-net-ajax-and-datetime-format-on-the-client
also can be used without AJAX.Net:
http://blog.stevenlevithan.com/archives/date-time-format/comment-page-3
Kenneth J
2009-12-07 17:20:24
This is overkill to inject the ASP.NET AJAX library into this solution. There are parts built in JavaScript for this.
Chris Love
2010-03-13 22:48:02