火车浏览器官方论坛

 找回密码
 立即注册
查看: 5736|回复: 2
打印 上一主题 下一主题

js 转换时间戳的例子

[复制链接]

2

主题

7

帖子

66

积分

注册会员

Rank: 2

积分
66
跳转到指定楼层
楼主
发表于 2019-8-29 09:15:42 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
自带只有时间转到时间戳,论坛也没找到方法,找客服会推荐用js或者C#。
万能百度找到的方法,贴论坛留个贴,希望能帮到你。

10位转时间
function Conversiontime(timestamp) {
                        var date = new Date(timestamp);
                        Y = date.getFullYear() + '-';
                        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
                        D = (date.getDate()<10?'0'+(date.getDate()):date.getDate()) + ' ';
                        h = (date.getHours()<10?'0'+(date.getHours()):date.getHours()) + ':';
                        m = (date.getMinutes()<10?'0'+(date.getMinutes()):date.getMinutes())+':';
                        s = (date.getSeconds()<10?'0'+(date.getSeconds()):date.getSeconds());
                        return Y+M+D+h+m+s;
           }
return Conversiontime({-var.时间戳-}* 1000);



13位转时间
function Conversiontime(timestamp) {
                        var date = new Date(timestamp);
                        Y = date.getFullYear() + '-';
                        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
                        D = (date.getDate()<10?'0'+(date.getDate()):date.getDate()) + ' ';
                        h = (date.getHours()<10?'0'+(date.getHours()):date.getHours()) + ':';
                        m = (date.getMinutes()<10?'0'+(date.getMinutes()):date.getMinutes())+':';
                        s = (date.getSeconds()<10?'0'+(date.getSeconds()):date.getSeconds());
                        return Y+M+D+h+m+s;
           }
return Conversiontime({-var.时间戳-});


然后将结果保留到变量就行了。


回复

使用道具 举报

2

主题

7

帖子

66

积分

注册会员

Rank: 2

积分
66
沙发
 楼主| 发表于 2020-4-22 14:11:25 | 显示全部楼层
刚准备感谢楼主,发现是我留的。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|火车浏览器  

GMT+8, 2024-5-9 04:38 , Processed in 0.121044 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表