【发布时间】:2014-04-28 09:30:51
【问题描述】:
所以基本上我做了一个增加时钟时间的计算:
function Clock(year,month,day,hours,minutes,seconds){
if(seconds !== null){
this.seconds = seconds;
}
if(minutes !== null){
this.minutes = minutes;
}
if(hours !== null){
this.hours = hours;
}
if(day !== null){
this.day = day;
}
if(month !== null){
this.month = month;
}
if(year !== null){
this.year = year;
}
}
function incrementClock(){
clock.seconds++;
if (clock.seconds >=60) {
clock.seconds = 0;
clock.minutes++;
if (clock.minutes >=60) {
clock.minutes = 0;
clock.hours++;
if (clock.hours >=24) {
clock.hours = 0;
clock.days++;
}
}
}
}
function showClock(){
//prints clock in format yyyy/mm/dd hh:mm:ss
}
这将相应地增加秒、分钟、小时和天...
因此,如果我每秒调用 print 时钟,它将如下所示:
var c = new Clock(2014,04,01,12,13,01);
showClock();
2014/4/1 12:13:1
我被困在月份部分......
我的问题是,由于每个月的天数不同,我该如何检查一个月是否已过?
编辑
我正在创建自己的缩小日期函数...所以请不要推荐使用 Date 对象,因为我正在尝试实现自己的对象
【问题讨论】:
-
(嘘——你应该检查
undefined而不是null。如果没有传递参数值,它将是undefined.)
标签: javascript clock