Javascript中string转date示例代码_javascript技巧

WBOY
Release: 2016-05-16 17:18:07
Original
1165 people have browsed it

把一个日期字符串如“2007-2-28 10:18:30”转换为Date对象:

1:

复制代码代码如下:

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:
复制代码代码如下:

var s = "2005-12-15 09:41:30";
var d = new Date(Date.parse(s.replace(/-/g, "/")));
Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!