在jQuery中转换UNIX时间戳 [英] Convert UNIX timestamp in jQuery

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

问题描述

好吧,我使用带有getJSON的php页面从我的表中获取时间戳。这是结构。

Well, I fetch timestamp from my table using a php page with getJSON. Here is the structure.

main.php - >使用getJSON(abc.php) - >我表中的值

main.php --> using getJSON (abc.php) --> value from my table

有没有办法将这个UNIX时间戳转换成这种格式:

Is there any way to convert this UNIX timestamp into this format:


dd-mm-yyyy at hh:mm am

dd-mm-yyyy at hh:mm am


推荐答案

Unix时间戳是1970年以来经过的秒数(纪元)。您需要将其转换为JS中的日期对象:

The Unix timestamp is the number of seconds elapsed since 1970 (epoch). You would need to convert that to a date object in JS:

var date = new Date(unixTimestamp*1000); // *1000 because of date takes milliseconds

一旦你有了日期对象,就可以使用任何一个以下帖子中提到的技术:
如何格式化JavaScript日期

Once you have the date object, you can use any of the techniques mentioned in the following post: How to format a JavaScript date

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

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