jQuery格式时间 [英] jQuery Format Time
本文介绍了jQuery格式时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个jQuery脚本,它在一个参数内以毫秒为单位接收一个字符串,如下所示:
I have a jQuery script that receives a string in milliseconds inside a parameter, like this:
params.tweetDate='77771564221';
我需要做的是创建一个jQuery函数,该函数将能够在美国时间格式化此毫秒字符串,例如10.00 AM
或10.00 PM
.
What I need to do is to create a jQuery function that will be able to format this milliseconds string in a USA time, like 10.00 AM
or 10.00 PM
.
是否有能够执行此操作的jQuery函数?
Is there a jQuery function that is able to do this?
请帮助.
谢谢
推荐答案
纯javascript中有Date对象,不需要jQuery. http://www.javascriptkit.com/jsref/date.shtml
There is Date object in pure javascript, no jQuery needed. http://www.javascriptkit.com/jsref/date.shtml
示例:
var time = new Date(params.tweetDate),
h = time.getHours(), // 0-24 format
m = time.getMinutes();
// next just convert to AM/PM format (check if h > 12)
这篇关于jQuery格式时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文