gpt4 book ai didi

javascript - 如何在javascript中计算两个日期时间之间的天数?

转载 作者:行者123 更新时间:2023-11-28 13:34:27 25 4
gpt4 key购买 nike

如何计算两个日期时间之间的天数?
请参阅下面我的代码:

<script type="text/javascript">
// how to count days between two date time ?
var a= '2014-03-21 12:00:12';
var b = '2014-05-11 18:00:00';
function days_diff(a,b){
// .....
// ..... placeholder ....
// ..... placeholder ....
// ..... placeholder ....
// ..... placeholder ....
// ..... placeholder ....
// .....
// var days = days_a - days_b;
return days;
}

</script>

最佳答案

  <script>
var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var firstDate = new Date(2008,01,12);
var secondDate = new Date(2008,01,22);
var diffDays = Math.round(Math.abs((firstDate.getTime()-secondDate.getTime())/(oneDay)));
</script>

关于javascript - 如何在javascript中计算两个日期时间之间的天数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22551506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com