I've got the following code for a jquery timer plugin. The compiler gives me the error: "Type 'number' is not assignable to type 'Date'"
$(function(){
var note = $('#note'),
ts = new Date(2012, 0, 1),
newYear = false;
if((new Date()) > ts){
ts = (new Date()).getTime() + 24*60*60*1000; //counting 24 hours
newYear = false;
}
});
});
};
You need to create a new instance of Date
:
if((new Date()) > ts){
ts = new Date((new Date()).getTime() + 24*60*60*1000);
newYear = false;
}
This way ts
is assigned with a new Date
with the given time.
Also, there's no need to create two instance of Date
for now, you can just put it in a variable an reuse it:
$(function(){
var note = $('#note'),
ts = new Date(2012, 0, 1),
newYear = false,
now = new Date();
if(now > ts){
ts = new Date(now.getTime() + 24*60*60*1000);
newYear = false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With