Home  >  Article  >  Web Front-end  >  Example code for converting string to date in Javascript_javascript skills

Example code for converting string to date in Javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:18:071214browse

Convert a date string such as "2007-2-28 10:18:30" into a Date object:

1:

Copy code The code 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])

2:
Copy code Code As follows:

var s = "2005-12-15 09:41:30";
var d = new Date(Date.parse(s.replace(/-/g, " /")));
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn