代码之家  ›  专栏  ›  技术社区  ›  Treby

灵活:向特定日期添加1天

  •  4
  • Treby  · 技术社区  · 14 年前

    如何在flex中设置添加1天的日期??

    5 回复  |  直到 12 年前
        1
  •  5
  •   Anthony    14 年前

    flex不是基于ecma(基本上是javascript)的吗?如果是的话,尝试向日期对象添加86400000毫秒?类似:

    var mili = 1000;
    var secs = 60;
    var mins = 60;
    var hours = 24;
    var day = hours * mins * secs * mili;
    var tomorrow = new Date();
    var tomorrow.setTime(tomorrow.getTime() + day);
    
        2
  •  3
  •   nishu    14 年前

    @treby建议的tommorow日期算法可以通过使用日期(年、月、日)构造函数这样使用:

    var now:Date = Date(); 
    var currentDate = now.date; 
    var currentMonth = now.month; 
    var currentYear = now.fullYear; 
    
    
    var tomorrow:Date = new Date(currentYear, currentMonth, currentDate + 1);  
    var lastWeek:Date = new Date(currentYear, currentMonth, currentDate  - 7); 
    var lastMonth:Date = new Date(currentYear, currentMonth-1, currentDate); 
    

    等。

        3
  •  3
  •   David Santa Olalla    14 年前

    用途:

    var date:Date = new Date();
    date.setDate(date.getDate() + 1);
    

    因为这考虑到了夏季时间的变化,即白天有23小时或25小时。

    干杯

        4
  •  2
  •   supervacuo    12 年前

    我从 this blog post 但这只是一个片段。

    用法很简单:

     dateAdd("date", +2); //now plus 2 days
    

    然后

    static public function dateAdd(datepart:String = "", number:Number = 0, date:Date = null):Date
    {
        if (date == null) {
            date = new Date();
        }
    
        var returnDate:Date = new Date(date.time);;
    
        switch (datepart.toLowerCase()) {
            case "fullyear":
            case "month":
            case "date":
            case "hours":
            case "minutes":
            case "seconds":
            case "milliseconds":
                returnDate[datepart] += number;
                break;
            default:
                /* Unknown date part, do nothing. */
                break;
        }
        return returnDate;
    }
    
        5
  •  1
  •   Arian Pasquali    14 年前

    或者,如果您正在寻找一个奇特的解决方案,您可以使用library flex-date实用程序 http://flexdateutils.riaforge.org/ 有很多有用的操作

    最好的

    推荐文章