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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -