Home > Web Front-end > JS Tutorial > Use JavaScript to format the date type read from the database into the desired type. _time date

Use JavaScript to format the date type read from the database into the desired type. _time date

WBOY
Release: 2016-05-16 18:48:11
Original
1283 people have browsed it
Copy code The code is as follows:

//Pass in the date type data taken from the database
function getformatdate(d){
var formate_datetime;
var array = d.split(" ");
var date = array[0];
var time = array[1];
var array_date = date.split("-");
var array_time = time.split(":");
var second = array_time[2].split(".")[0];
formate_datetime = array_date[0] "Year" removeZero(array_date[1]) "Month" removeZero(array_date[2]) "Day"
removeZero(array_time[0]) "Hour" removeZero(array_time[1] ) "minute" second "second";
return formate_datetime;
}
//Remove the 0 before the month, day, hour and minute
function removeZero(data)
{
if(data.charAt(0) == "0"){
return data.charAt(1);
}
else
{
return data;
}
}
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