Comparing two Date values in ActionScript - possible to compare whole day values?

非 Y 不嫁゛ 提交于 2019-12-13 17:29:33

问题


I need to be able to compare the number of whole days between two dates in ActionScript, is this possible?

I'd like to test if one date is 7 days or less after today, and if so is it one day or less (if it's before today this also counts).

The workaround I have in place is using the .time part of the date field:

// Get the diffence between the current date and the due date
var dateDiff:Date = new Date();
dateDiff.setTime (dueDate.time - currentDate.time);
if (dateDiff.time < ( 1 * 24 * 60 * 60 * 1000 ))
    return "Date is within 1 day");
else if (dateDiff.time < ( 7 * 24 * 60 * 60 * 1000 ))
    return "Date is within 7 days");

As I say - this is only a workaround, I'd like a permanent solution to allow me to check the number of whole days between 2 dates. Is this possible? Thanks


回答1:


var daysDifference:Number = Math.floor((dueDate.time-currentDate.time)/(1000*60*60*24));
if (daysDifference < 2)
   return "Date is within 1 day";
else if (daysDifference < 8)
   return "Date is within 7 days";


来源:https://stackoverflow.com/questions/7298635/comparing-two-date-values-in-actionscript-possible-to-compare-whole-day-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!