信息发布→ 登录 注册 退出

js 时间格式与时间戳的相互转换示例代码

发布时间:2026-01-11

点击量:
一.时间转换时间戳
复制代码 代码如下:
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;
}
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!