jquery datepicker时间改变
最近几天,我遇到了使用 jquery datepicker 计算日期差异的奇怪行为, 当我试图找出 3 月 28 日的两个日期的天数差异时。差异不是按预期返回整数,而是给我一个略小于预期整数的浮点数。
我的意思是,3 月 25 日
和 3 月 28 日
之间的差异应该是 3
天,但它给了我 2.9583333333333335
天。
每当 3 月 28 日在范围内时,我就会得到这个奇怪的结果。
我想这是由于时间变化造成的。 对于任何其他范围,这个问题都不会发生。
我已经找到了如何用一些简单的数学来解决这个问题:
Math.floor((b-a)/(1000*60*60*24)+0.05);
是时间的变化导致了奇怪的结果吗?或者只是我的代码?
这是一些代码(jquery日期选择器示例的修改),其中显示:
谢谢
Last days I was facing a strange behavior calculating date diff with jquery datepicker,
when I try to find out the difference in days of two dates crossing the 28th march. The difference, instead of returning an integer number as expected, gives me a float number slightly less than the integer expected.
I mean, the difference between 25th march
and 28th march
should be 3
days but it gives me 2.9583333333333335
days.
Whenever the 28th march is within the range I get this weird result.
I guess this is due to the time changing.
With any other range that problem doesn't fire.
I've found out how to solve this problem with some easy mathematics:
Math.floor((b-a)/(1000*60*60*24)+0.05);
Is it the time changing that leads to that weird result? Or is just my code?
here is some code (modification of a jquery date-picker example) which shows that:
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该是因为时间的变化。如果将该小数乘以 24 小时,则得到 23。
秋季,当时间倒退一小时时,范围内会发生什么
Has to be due to the time change. If you multiply that decimal by 24 hours, you get 23.
What happens during the range when the hour goes back an hour in the fall