Home  >  Article  >  Web Front-end  >  Detailed explanation of method examples of JS converting date strings into Date date objects

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

怪我咯
怪我咯Original
2017-06-29 10:19:231739browse

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

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, "/")));

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!

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