Parsing The Date In Mm/dd/yy Format
I get the response for the Date in this format while showing in the text box, how do i covert it to MM/DD/YYYY and Again re covert it to back to this format while sending /Date(130
Solution 1:
functiondateToString(date) {
return (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getYear();
}
functiondateFromString(str) {
return new Date(str);
}
Note, that month begins from 0
.
Solution 2:
To convert the regExp-like string to a real Date Object
you could use:
var dateNum = Number('/Date(1306348200000)/'.replace(/[^0-9]/g,''))
, dat = newDate(dateNum); //=>Date {Wed May 25 2011 20:30:00 GMT+0200}
To display formatted dates I use my own small library, which may be of use to you.
Solution 3:
var s = '/Date(1306348200000)/';
// convert to javascript datevar date = newDate(parseInt(s.substr(6, 13))); // removes /Date( & )/// format the datefunctionpad(n) { return n < 10 ? '0' + n : n; } // leading zerosvar ddmmyy = pad(date.getDate()) + '/' + pad(date.getMonth() + 1) + '/' + date.getFullYear().toString().substr(2);
// convert back
s = '/Date(' + date.getTime() + ')/';
Solution 4:
here you can find everything regarding javascript dates http://www.w3schools.com/js/js_obj_date.asp
Post a Comment for "Parsing The Date In Mm/dd/yy Format"