Javascript setHours have unexpected behaviour for UTC+2 timezones
I have following javascript function
function DateIncrement(_Date,_Inc)
{
return (new Date((new Date(_Date)).setHours(_Inc*24,0,0,0)))
}
The purpose is to increment _Date by开发者_JS百科 _Inc days. This works fine for all the timezone except UTC+2 time zones (Amman, Cairo, Beirut etc.) For UTC+2 time zones it does not return next day. It set hours in _Date to 24.
Thanks in advance.
If you're trying to increment a JS Date by n days, why don't you use setDate()
?
function DateIncrement(_Date,_Inc)
{
var date = new Date(_Date);
date.setDate(date.getDate() + _Inc);
return date;
}
... if you really need to set it to midnight, then use setHours()
afterwards.
精彩评论