This article describes the method of converting a date string into a Date date object in JavaScript. Share it for your reference. The details are as follows:
Here, convert a date string such as "2014-4-28 12:31:45" into a Date object:
Method 1:
The code copy is as follows: var strArray=str.split(" ");
var strDate=strArray[0].split("-");
var strTime=strArray[1].split(":");
var a=new Date(strDate[0],(strDate[1]-parseInt(1)),strDate[2],strTime[0],strTime[1],strTime[2])
Method 2 (super simple):
The code copy is as follows: var s = "2005-12-15 09:41:30";
var d = new Date(Date.parse(s.replace(/-/g, "/")));
I hope this article will be helpful to everyone's JavaScript programming.