zoukankan      html  css  js  c++  java
  • 时间的基本处理

    输出2017-03-05格式

    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if(month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if(strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    };
    getNowFormatDate();

    处理结束时间不小于开始时间

    var currentdate;
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if(month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if(strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    };
    getNowFormatDate();
    $('.start_date_input').val(currentdate);
    $('.start_date').datetimepicker({
        format: 'yyyy-mm-dd',
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        minView: "month"
    });
    $('.end_date_input').val(currentdate);
    $('.end_date').datetimepicker({
        format: 'yyyy-mm-dd',
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        minView: "month"
    });
    $('.date_input').on('change', function() {
        var $this = $(this);
        var thisValue = new Date($this.val()).valueOf(),
            anotherValue = new Date($('.date_input').not(this).val()).valueOf();
        if($this.is('.start_date_input')) {
            if(thisValue > anotherValue) {
                wxcepAlert('开始日期不能大于结束日期');
                $this.val('');
            }
        } else {
            if(thisValue < anotherValue) {
                wxcepAlert('开始日期不能大于结束日期');
                $this.val('');
            }
        }
    });
    日常所遇,随手而记。
  • 相关阅读:
    【问题】解决python3不支持mysqldb
    《Craking the Coding interview》python实现---02
    《Craking the Coding interview》python实现---01
    python标准库--functools.partial
    Multimodal Machine LearningA Survey and Taxonomy
    概率热图的绘制--gradcam
    Pytorch 技巧总结(持续更新)
    linux教训
    Destruction and Construction Learning for Fine-grained Image Recognition----论文
    Ubuntu16.04+3090+cuda11.0+cudnnV8+pytorch-nightly
  • 原文地址:https://www.cnblogs.com/zhihou/p/8939990.html
Copyright © 2011-2022 走看看