Unix 时间 javascript [英] Unix time javascript

查看:34
本文介绍了Unix 时间 javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
在 Javascript 中将 Unix 时间戳转换为时间

我试图从 unix 时间返回一个格式化的时间.unix时间为1349964180.

I am trying to return a formatted time from a unix time. The unix time is 1349964180.

如果您访问 unixtimestamp.com 并插入 1349964180 对于时间戳,您将获得:

If you go to unixtimestamp.com and plug in 1349964180 for Timestamp you will get:

TIME STAMP: 1349964180

DATE (M/D/Y @ h:m:s): 10 / 11 / 12 @ 9:03:00am EST

这就是我想要的,但在 javascript 中.

This is what I want, but in javascript.

比如:

function convert_time(UNIX_timestamp){
......
......
return correct_format;
}

然后调用:convert_time(1349964180);

和 console.log 应该打印:10/11/12 @ 9:03:00am EST

and console.log should print: 10 / 11 / 12 @ 9:03:00am EST

推荐答案

你可以试试这个

function convert_time(ts) {
   return new Date(ts * 1000) 
}

然后这样称呼它

console.log(convert_time(1349964180));

这篇关于Unix 时间 javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆