如何做Flex的最新演绎和另外 [英] How to do Flex date deduction and addition
问题描述
在Flex中,我试图做的最新演绎和补充,但无法找到一个方法来做到这一点。
In flex, I am trying to do date deduction and addition, but couldn't find a way to do it.
例如: 公共变种dateNow:日期=新的日期();
e.g.: public var dateNow:Date=new Date();
我怎样才能获得之日起3个月前比dateNow?
How can I get the Date 3 months earlier than dateNow?
谢谢!
推荐答案
您可以使用日期构造这一点。第一个参数为Date的构造函数采用一年或一个时间戳。您可以使用 Date.time
属性得到Date对象中的时间戳。一旦你的时间戳可以加/减,从它秒数,然后把它传递给新的日期(时间戳)
,你会得到它重新$一个全新的日期p $ psents新的时间戳。
You can use the Date constructor for this. The first argument to Date's constructor takes either a year or a timestamp. You can use the Date.time
property to get the timestamp from a date object. Once you have the timestamp you can add/subtract some number of seconds from it, and then pass it to new Date(timestamp)
and you get a brand new date which represents the new timestamp.
Edit(编辑) 作为一个评论者所指出的,操作时间可能不是最好的一段路要走。但你仍然可以使用日期构造如下:
Edit; As a commenter pointed out, time manipulation may not be the best way to go. But you can still use the Date constructor as follows:
var now:Date = new Date();
var threeMonthsAgo = new Date(now.fullYear,
now.month - 3,
now.date,
now.hour,
now.minute,
now.second,
now.millisecond);
Date构造函数是足够聪明的处理负值,或值大于11
The Date constructor is smart enough to deal with negative values, or values greater than 11.
这篇关于如何做Flex的最新演绎和另外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!