jQuery javascript时钟可设置的时间
jQuery javascript clock with settable time?
我正在寻找一个简单的jQuery时钟。
有吨在那里,但我正在寻找一个,我可以设置当前时间,和输出格式。
所以我希望能够调用像
这样的东西$('#clock').clock({
format: 'l dS F Y, h:i a', //PHP date format, but anything that can mimic this output is good
date: '2012-07-01 23:59:59' //MYSQL date format, but can output as anything
});
是否有这样的东西(即使是原始的js也会这样做)。
为时钟创建计数器非常简单,您可能可以用更少的时间来编写一个计数器,而不是在这里查看您将得到的答案。下面是我做的一个原型继承的例子。
只是格式化输出,但你喜欢,添加CSS你的心内容,使其看起来不错。
// Create a digital clock
// Write time in hh:mm:ss.nnn format
// el is an element
function Clock(el) {
if (typeof el == 'string') el = document.getElementById(el);
this.el = el;
}
// Clock methods
Clock.prototype = {
// Utilty functions
addZ: function(n) {
return n < 10? '0' + n : '' + n;
},
addZZ: function(n) {
return n < 10? '00' + n : n < 100? '0' + n : '' + n;
},
formatTime: function(d) {
return this.addZ(d.getHours()) +
':' + this.addZ(d.getMinutes()) +
':' + this.addZ(d.getSeconds()) +
// Milliseconds are just for debug, remove from finished version
'.' + this.addZZ(d.getMilliseconds())
},
update: function() {
var clock = this;
var d = new Date();
// Set next run to just after full second
var interval = 1020 - d.getMilliseconds()
this.el.innerHTML = this.formatTime(d);
setTimeout(function(){
clock.update();
}
,interval);
}
};
// Create a new clock
// el is id or element to display text in
function newClock(el) {
var y = new Clock(el);
y.update();
}
编辑
通用日期格式函数:http://blog.stevenlevithan.com/archives/date-time-format
将日期格式化为Tuesday 05th July 2011, 10:31 am:
var formatDate = (function() {
// Days of the week, zero is Sunday
var days = ['Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday'];
// Months of the year, zero is January
var months = ['January','February','March','April',
'May','June','July','August','September',
'October','November','December'];
// Format single digit numbers
function addZ(n) {
return n<10? '0' + n : '' + n;
}
// Add ordinal to numbers
function addOrdinal(n) {
return ['th','st','nd','rd'][(''+n).slice(-1)] || 'th';
}
return function (date) {
var d = addZ(date.getDate());
var h = date.getHours();
var ap = h < 12? 'am' : 'pm';
h = addZ(h > 12? h - 12 : h);
return days[date.getDay()] + ' '
+ d + addOrdinal(d) + ' '
+ months[date.getMonth()] + ' '
+ date.getFullYear() + ', '
+ h + ':'
+ addZ(date.getMinutes()) + ' '
+ ap
}
}());
相关文章:
- 更改默认时区后,如何在本地时间设置时刻格式
- 使用HTML5 Navigation Timing API时,导航开始时间设置为0
- 具有完整时间设置的嵌套 JQuery 动画
- 清除间隔在 6 个时间设置后不起作用间隔
- JQuery 日期选择器 - 根据当前时间设置 MinDate
- 通过Javascript错误将考试时间设置为30分钟
- 如何将东部标准时间设置为日期选择器 (jquery ui) - 使用 javascript
- 如何在javascript中将当前时间设置为其他时间
- 使用JS根据时间设置列的背景颜色
- 如何将一些指定的时间设置为ajax调用,这样如果请求正在花费时间检索数据,它应该来到FAIL块
- 如何将时间设置为定期?JAVA
- 根据一天中的时间设置默认选项的选定值
- 将默认时间设置为mobisroll时间选择器
- 如何在正确的时间设置JS事件
- 客户端时间设置在javascript中破坏了可读日期
- jQuery Timepicker和jQuery Datepair:如何将结束时间设置为15分钟
- Bootstrap DateTimePicker将时间设置为午夜
- 如何将这种日期时间设置为“2013-03-12T22:15:40+08:00”到“12 Mar 2012 02:15:4
- 使用php服务器时间设置Javascript时间
- 如何实现将新的Firebase自定义身份验证最大过期时间设置为1小时的用例