我需要创建一个只包含1列的表(从4小时开始),每行增加10秒。所以需要看起来像这样:
04hrs 00mins 00secs - 04hrs 00mins 09secs
04hrs 00mins 10secs - 04hrs 00mins 19secs
04hrs 00mins 20secs - 04hrs 00mins 29secs
.....
06hrs 59mins 50secs - 06hrs 59mins 59secs
这显然需要很长时间才能使用硬代码,因此我希望动态创建它。基于我目前正在努力学习的内容,我希望能够使用jquery或asp.net(vb)来做到这一点,但只要有效,任何事情都可以做到!
由于
答案 0 :(得分:1)
基本日期时算术。
// format the given date in desired format
// ignores date portion; adds leading zeros to hour, minute and second
function fd(d){
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
return (h < 10 ? '0'+h : h) + 'hrs ' +
(m < 10 ? '0'+m : m) + 'mins '+
(s < 10 ? '0'+s : s) + 'secs';
}
// 1) 10800 seconds = 3600 * 3 = 3 hours
// 2) a+=10 increments seconds counter in 10-second interval
for ( var a = 0; a < 10800; a+=10 ) {
// an arbitrary date is chosen, we're more interested in time portion
var b = new Date('01/01/2000 04:00:00');
var c = new Date();
b.setTime(b.getTime() + a*1000);
// c is b + 9 seconds
c.setTime(b.getTime() + 9*1000);
$("#table1").append(
"<tr><td>" + fd(b) + ' - ' + fd(c) + "</td></tr>"
);
}
请参阅输出here。我认为您可以轻松地将此代码示例移植到ASP.Net/VB.Net/C#。