[英]Get difference in days of two different dates in same ASPxDateEdit Control with javascript
[英]How to get rid off age in days error in JavaScript. getting same age difference for two continue dates of different months
我正在使用以下 JavaScript function (脚本)来计算年龄(以天为单位)。 它给出了一个月的最后一天和下个月的第一天的相同年龄。 例如,它为 31/05/2016 和 01/06/2016 提供 1400 天的年龄。 谁能帮我找到并解决问题? 提前致谢。
function ageindays(birthDate){
var yearThen = parseInt(birthDate.substring(0,4), 10);
var monthThen = parseInt(birthDate.substring(5,7), 10);
var dayThen = parseInt(birthDate.substring(8,10), 10);
var today = new Date();
var birthday = new Date(yearThen, monthThen, dayThen);
var differenceInMilisecond = today.valueOf() - birthday.valueOf();
var diffindays = differenceInMilisecond/86400000
console.log(diffindays);
}
console.log("First date calculation")
ageindays("2016-06-01")
console.log("Next date calculation")
ageindays("2016-05-31")
答案在于如何在 javascript 中枚举日期。 月份被枚举为 0-11,这意味着您必须将月份转换为 1 才能获得体面的响应。
当日期不存在时:6 月 31 日不存在,它只是流到 7 月:7 月第一。
所以两个样本日期:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.