how to convert date value through jquery
I'm getting below value for a datepicker control in Jquery,
Mon May 9 00:00:00 UTC+0530 2011
Now I need to convert the above value to below string "5/9/2011"开发者_JS百科.
Please help....
Not a jQuery issue - see the Javascript Date Object documentation
var d = new Date('Mon May 9 00:00:00 UTC+0530 2011');
var d_formatted = d.getDate() + '/' + d.getMonth() '/' + d.getFullYear();
You can make a Date
object from the text with new Date
, then simply make a string using the methods on the Date
object, i.e.:
var date = new Date(someDate);
var str = date.getMonth() + "/" + date.getDate() + "/" + date.getFullYear();
Looking at the format of your date, it is probably already a Date
object that is being represented as a string, so invoking the appropriate methods on it (second line) will give you the representation you want.
Try this:
$( ".selector" ).datepicker({ dateFormat: 'mm/dd/yy' });
精彩评论