Home > Web Front-end > JS Tutorial > Sample code for mutual conversion between js time format and timestamp_javascript skills

Sample code for mutual conversion between js time format and timestamp_javascript skills

WBOY
Release: 2016-05-16 17:07:06
Original
1203 people have browsed it
1. Time conversion timestamp
Copy code The code is as follows:

function transdate(endTime){
var date=new Date();
date.setFullYear(endTime.substring(0,4));
date.setMonth(endTime.substring(5,7)- 1);
date.setDate(endTime.substring(8,10));
date.setHours(endTime.substring(11,13));
date.setMinutes(endTime.substring(14, 16));
date.setSeconds(endTime.substring(17,19));
return Date.parse(date)/1000;
}

2. Timestamp conversion time
(1): converted to 2011-3-16 16:50:43 Format:
Copy code The code is as follows:

function getDate(tm){
var tt=new Date(parseInt(tm) * 1000).toLocaleString().replace(/year| Month/g, "-").replace(/日/g, " ")
return tt;
}

(2): Convert to March 16, 2011 16:50:43:
Copy code The code is as follows:

function getDate(tm){
var tt=new Date(parseInt(tm) * 1000).toLocaleString()
return tt;
}

(3): Convert to March 16, 2011 16:50
Copy code The code is as follows:

function getDate(tm){
var tt=new Date(parseInt(tm) * 1000).toLocaleString().substr(0,16);
return tt;
}
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