• 9.25 学习下日期加减


    垫款日期要限制预计还款日期,当前用的是bootstrap-datetimepicker插件,封装后使用方法如下:

    datePirck: function(){ 	
    	MJJS.ui.timepicker('.d2d', {
    		format: "yyyy-mm-dd",
    		showMeridian: true,
    		startView: 2,
    		startDate: new Date(),
    		autoclose: true,
    	}),
    }
    

    需要设置一个endDate。我一开始设想endDate: new Date(),但是这样写日期选择器直接显示1899年。。。

    然后查了一下,改成这样:

    endDate: new Date((new Date()).getTime()-86400000*3),
    

    还是不对。。。 

    不知道怎么写了,请教了wd,这样写:

    datePirck: function(){ 
    	var now  = new Date();//Date 对象自动使用当前的日期和时间作为其初始值
    	console.log('1:'+now);//1:Mon Sep 25 2017 15:54:44 GMT+0800 (中国标准时间) 

         //getTime() 方法可返回距 1970 年 1 月 1 日之间的毫秒数。
    console.log('now.getTime():'+now.getTime());//now.getTime():1506326084338
    //setTime() 向 1970/01/01 添加毫秒,并显示新的日期和时间。
         //此处setTime()的参数为当前日期加上20天的毫秒数,即20天后距 1970/01/01的毫秒数
         now.setTime(now.getTime()+20*86400000); console.log('2:'+now);//2:Sun Oct 15 2017 15:54:44 GMT+0800 (中国标准时间),这是20天后的日期 MJJS.ui.timepicker('.d2d', { format: "yyyy-mm-dd", showMeridian: true, startView: 2, startDate: new Date(), endDate: end, autoclose: true, }); },

    这样就可以了。查了下手册发现原来setTime只是其中一种,还有setDate(),setMonth(),setFullYear()

    那我们可以直接使用setDate()呀!

    var now  = new Date();
    now.setDate(now.getDate() + 20);
    this.$repayDate.datetimepicker({
         startDate: new Date(),
         endDate: now
    });
    

    这样更简洁了。 

  • 相关阅读:
    Codeforces 813F Bipartite Checking 线段树 + 并查集
    Codeforces 263E Rhombus (看题解)
    Codeforces 173E Camping Groups hash
    Codeforces 311C Fetch the Treasure 取模意义下的最短路 (看题解)
    R 培训之 Table
    Docker命令详解
    Celery的实践指南
    Using Celery with Djang
    PostgreSQL
    改时区参考
  • 原文地址:https://www.cnblogs.com/yan89/p/7592570.html
Copyright © 2020-2023  润新知