如何计算两个 ActionScript Date 对象之间的差异(以月为单位)?
我必须验证 1) 结束日期不小于开始日期,2) 两个 UTC 日期之间的差异不超过 12 个月。为此,我需要一个 monthDifference
函数:
public static function monthDifference(start:Date, end:Date):int;
由于部分月份可能会令人困惑,因此月份差异应该如何工作:
- 2010 年 1 月 1 日和 2010 年 1 月 31 日之间的月份差异为零<强>(0)。
- 2010 年 1 月 31 日与 2010 年 2 月 1 日之间的月份相差一(1)。
- 2010 年 1 月 1 日与 2010 年 2 月 28 日之间的月份相差一(1)。
- 2010 年 1 月 1 日与 2010 年 3 月 1 日之间的月份相差两个(2)。
如何计算 ActionScript 3.0 中的月份差异?
I have to validate that 1) the end Date is not less than the start Date and 2) the difference between the two UTC Dates is not more than 12 months. To do this, I need a monthDifference
function:
public static function monthDifference(start:Date, end:Date):int;
Since partial months can be confusing, this is how month differences are supposed to work:
- The month difference between January 1, 2010 and January 31, 2010 is zero (0).
- The month difference between January 31, 2010 and February 1, 2010 is one (1).
- The month difference between January 1, 2010 and February 28, 2010 is one (1).
- The month difference between January 1, 2010 and March 1, 2010 is two (2).
How can I calculate month difference in ActionScript 3.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我想出的...
如果有任何错误请告诉我!
This is what I came up with...
Please let me know if there's any error!
此处列出了一个相当可靠的内容。我没有找到作者的名字,udayms 是他的博客用户名。
从他的班级中摘录:
There is a pretty solid one listed here. I didn't find the authors name, udayms is his user name for the blog.
Pulled from his class:
这并不容易,因为你必须用闰年来计算!我认为你应该看看DateUtils.as 来自 AS3Commons-lang 库。有一个非常有用的方法,称为
addMonths()
,它可以帮助您,因为它处理无效日期。It is not so easy because you have to count with leap years! I think you should look at DateUtils.as from AS3Commons-lang library. There is a really useful method called
addMonths()
which could help you because it deals with invalid dates.