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

How to use JS to format the date type read from the database into the desired type

怪我咯
Release: 2018-05-26 16:41:50
Original
2489 people have browsed it

When the page is initialized, use JavaScript to format the date type read from the database into the desired type. Format it as yyyy year MM month dd day HH hour mm minute ss second. You can refer to the code and play freely.

The code is as follows:

//传入从数据库中取出的日期类型数据 
function getformat
date
(d){ 
var formate_date
time
; 
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] + "年" + removeZero(array_date[1]) + "月" + removeZero(array_date[2]) + "日 " 
+ removeZero(array_time[0]) + "时" + removeZero(array_time[1]) + "分" + second + "秒"; 
return
 formate_datetime; 
} 
//去掉月、日、时、分前的0 
function removeZero(data) 
{ 
if(data.charAt(0) == "0"){ 
return data.charAt(1); 
} 
else
 
{ 
return data; 
}
}
Copy after login

The above is the detailed content of How to use JS to format the date type read from the database into the desired type. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!