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

Detailed explanation of method examples of JS converting date strings into Date date objects

怪我咯
Release: 2017-06-29 10:19:23
Original
1733 people have browsed it

This article mainly introduces the method of javascriptconverting datestring into Datedateobject, which is a very practical conversion For tips, friends who need them can refer to

The example in this article describes the method of converting a date string into a Date object in 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:

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])
Copy after login

Method 2 (super simple):

The code is as follows:

var s = "2005-12-15 09:41:30"; 
var d = new Date(Date.parse(s.replace(/-/g, "/")));
Copy after login

The above is the detailed content of Detailed explanation of method examples of JS converting date strings into Date date objects. For more information, please follow other related articles on the PHP Chinese website!

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