Home > Web Front-end > JS Tutorial > body text

JavaScript method to convert date string into Date date object_javascript skills

WBOY
Release: 2016-05-16 16:14:03
Original
1291 people have browsed it

The example in this article describes the method of converting a date string into a Date object using JavaScript. Share it with everyone for your reference. The details are as follows:

Here is how to convert a date string such as "2014-4-28 12:31:45" into a Date object:

Method 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])

Method 2 (super simple):

Copy code The code 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 design.

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
Popular Tutorials
More>
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!