一.时间转换时间戳
复制代码 代码如下:
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;
}
二.时间戳转换时间
(1):转换成 2011-3-16 16:50:43 格式:
复制代码 代码如下:
function getDate(tm){
var tt=new Date(parseInt(tm) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ")
return tt;
}
(2):转换成 2011年3月16日 16:50:43:
复制代码 代码如下:
function getDate(tm){
var tt=new Date(parseInt(tm) * 1000).toLocaleString()
return tt;
}
(3):转换成 2011年3月16日 16:50
复制代码 代码如下:
function getDate(tm){
var tt=new Date(parseInt(tm) * 1000).toLocaleString().substr(0,16);
return tt;
}
您可能感兴趣的文章:
- Vue.js 时间转换代码及时间戳转时间字符串
- javascript时间戳和日期字符串相互转换代码(超简单)
- js获取时间并实现字符串和时间戳之间的转换
- js实现把时间戳转换为yyyy-MM-dd hh:mm 格式(es6语法)
- js时间戳与日期格式之间相互转换
- JS获取时间的相关函数及时间戳与时间日期之间的转换
- js与C#进行时间戳转换
- 时间戳转换为时间 年月日时间的JS函数
- JS将时间秒转换成天小时分钟秒的字符串