AS2:计算两个日期之间的天 [英] AS2: Calculate days between two dates
问题描述
我使用这个脚本目前确定两个日期之间的区别:
I use this script currently to determine the difference between two dates:
// Slide_Tracker[?].date_int are results from the built in function getTime()
var current_date = new Date(Slide_Tracker[i].date_int);
var past_date:Date = new Date(Slide_Tracker[i - 1].date_int);
var date_diff:Number = Math.round((current_date - past_date) / 86400000);
这个问题是我要监控的实际物理一天的变化,所以如果有人访问你的应用,下午11:59再回来在5分钟后,这将是1天相差注册(新的一天),该当前脚本需要ATLEAST 12小时有两个日期之间传递它注册为新的一天。
The problem with this is I want to monitor the actual physical day change so if someone accessed the application at 11:59 PM and then came back 5 minutes later this would register as a 1 day difference (a new day), this current script requires atleast 12 hours to have passed between two dates for it to register as a new day.
我曾想过使用日期号码等,但由于几个月甚至几年都如此不同,它是一个相当复杂的路线,必须有更简单的东西。
I have thought about using the date number etc, but because months and years are so different it is quite a complex route, there must be something simpler.
推荐答案
作为一个供参考,下面AM的日期和午夜之间的区别是:
As an FYI, the difference between a date and midnight of the following AM is:
// dt is the start date
var diff:Number =
new Date(dt.getYear(), dt.getMonth(), dt.getDate() + 1) - dt.getTime()
但它是最简单的只是一轮第二天,然后从那里开始:
But it is easiest to simply round to the next day and then start from there:
var dt:Date = new Date(Slide_Tracker[i - 1].date_int);
var past_date = // start at the next day to only deal w/ 24 hour increments
new Date(dt.getYear(), dt.getMonth(), dt.getDate() + 1);
dt = new Date(Slide_Tracker[i].date_int);
var current_date =
new Date(dt.getYear(), dt.getMonth(), dt.getDate() + 1);
var date_diff:Number = Math.round((current_date.getTime() -
past_date.getTime()) / 86400000);
您的另一种选择是圆输入:
Your other option is to round the inputs:
// rounds a timestamp *down* to the current day
function getBaseDay(val:Number):Number
{
return Math.floor( val / 86400000 ) * 86400000
}
var current_date = new Date(getBaseDay(Slide_Tracker[i].date_int));
var past_date:Date = new Date(getBaseDay(Slide_Tracker[i - 1].date_int));
var date_diff:Number = Math.round((current_date.getTime() -
past_date.getTime()) / 86400000);
这篇关于AS2:计算两个日期之间的天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!