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('');
            }
        }
    });
    日常所遇,随手而记。
  • 相关阅读:
    DNS 截持模拟及环境搭建
    Ant、Gradle、Python三种打包方式的介绍
    oc/c/c++混编老文,写的很好,mark
    好文!关于iOS下的正则表达式实战案例
    Java设计模式——享元模式
    Java 消息机制之回调详解
    windows版爬取csdn
    14.6.2 Configuring InnoDB for Read-Only Operation
    dump iot表
    heap表按字符串和数值型排序规则
  • 原文地址:https://www.cnblogs.com/zhihou/p/8939990.html
Copyright © 2011-2022 走看看