admin管理员组文章数量:1026989
Based on a given millisecond timestamp, what's the 'correct' way to get the next day, week, month, year, etc.? That is, without having to do some kind of binary search with raw millisecond timestamp values or something silly like that.
Edit: Does using the Date constructor with a month, day, hour, etc. value beyond the limit translate it to the next year, month, day, etc.?
Based on a given millisecond timestamp, what's the 'correct' way to get the next day, week, month, year, etc.? That is, without having to do some kind of binary search with raw millisecond timestamp values or something silly like that.
Edit: Does using the Date constructor with a month, day, hour, etc. value beyond the limit translate it to the next year, month, day, etc.?
Share Improve this question edited Dec 9, 2010 at 23:19 Hamster asked Dec 9, 2010 at 22:38 HamsterHamster 3,1627 gold badges30 silver badges38 bronze badges2 Answers
Reset to default 4function getNextDate()
{
var today = new Date();
var d = today.getDate();
var m = today.getMonth();
var y = today.getYear();
var NextDate= new Date(y, m, d+1);
var Ndate=NextDate.getMonth()+1+"/"+NextDate.getDate()+"/"+NextDate.getYear();
alert(Ndate);
}
If the millisecond timestamp that you have is (conveniently!) the number of milliseconds since 1970/01/01 then you can simply create a new Date object from the millisecond value new Date(milliseconds)
and use it as outlined in Misnomer's answer.
If your timestamp is based from onther point in time then you can simply workout the offset (in milliseconds) from 1970/01/01 and subtract that from the timestamp before creating the Date object.
As always when dealing with dates, be clear if you are dealing in local or UTC times.
w3schools date object
w3schools full date reference
Based on a given millisecond timestamp, what's the 'correct' way to get the next day, week, month, year, etc.? That is, without having to do some kind of binary search with raw millisecond timestamp values or something silly like that.
Edit: Does using the Date constructor with a month, day, hour, etc. value beyond the limit translate it to the next year, month, day, etc.?
Based on a given millisecond timestamp, what's the 'correct' way to get the next day, week, month, year, etc.? That is, without having to do some kind of binary search with raw millisecond timestamp values or something silly like that.
Edit: Does using the Date constructor with a month, day, hour, etc. value beyond the limit translate it to the next year, month, day, etc.?
Share Improve this question edited Dec 9, 2010 at 23:19 Hamster asked Dec 9, 2010 at 22:38 HamsterHamster 3,1627 gold badges30 silver badges38 bronze badges2 Answers
Reset to default 4function getNextDate()
{
var today = new Date();
var d = today.getDate();
var m = today.getMonth();
var y = today.getYear();
var NextDate= new Date(y, m, d+1);
var Ndate=NextDate.getMonth()+1+"/"+NextDate.getDate()+"/"+NextDate.getYear();
alert(Ndate);
}
If the millisecond timestamp that you have is (conveniently!) the number of milliseconds since 1970/01/01 then you can simply create a new Date object from the millisecond value new Date(milliseconds)
and use it as outlined in Misnomer's answer.
If your timestamp is based from onther point in time then you can simply workout the offset (in milliseconds) from 1970/01/01 and subtract that from the timestamp before creating the Date object.
As always when dealing with dates, be clear if you are dealing in local or UTC times.
w3schools date object
w3schools full date reference
本文标签:
版权声明:本文标题:datetime - Javascript, Time and Date: Getting the next day, week, month, year, etc - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1744272298a2089067.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论