javascript - How to convert Dec 2 1991 12:00AM to 12/02/1991 -
var str = "dec 02 1991 12:00"; var new_date = str.substring(0,str.length - 6); var dateofbirth = $filter('date')(new date(new_date), 'mm/dd/yyyy');
you don't need jquery this.
you can parse date using 'date' constructor: new date("dec 02 1991 12:00")
.
then have date object in have methods month, day , year (see documentation).
here example trying achieve:
var str = "dec 02 1991 12:00"; var date = new date(str); var month = date.getutcmonth(); var day = date.getutcday(); var year = date.getutcfullyear(); var dateofbirth = ((month < 10 ? "0" : "") + month) + "/" + ((day < 10 ? "0" : "") + day) + "/" + year;
Comments
Post a Comment