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

Example code for converting string to date in Javascript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:18:07
Original
1266 people have browsed it

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, " /")));
Related labels:
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 Issues
Convert string to date in Laravel
From 1970-01-01 08:00:00
0
0
0
Format date string
From 1970-01-01 08:00:00
0
0
0
javascript - python small algorithm
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template