火车浏览器官方论坛

 找回密码
 立即注册
查看: 5708|回复: 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 | 只看该作者
刚准备感谢楼主,发现是我留的。
回复 支持 反对

使用道具 举报

0

主题

3

帖子

8

积分

企业版

积分
8
板凳
发表于 2020-12-16 13:48:15 | 只看该作者
感谢楼主,收藏了
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-27 11:06 , Processed in 0.080900 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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