• 时间的基本处理


    输出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('');
            }
        }
    });
    日常所遇,随手而记。
  • 相关阅读:
    vue路由动态过渡效果
    完美解决safari、微信浏览器下拉回弹效果
    从零开始搭建VUE项目
    上传图片(photoClip)
    手机移动端input date placehoder不显示
    evaluate-reverse-polish-notation
    Minimum Depth of Binary Tree
    前端学习02-01分帧的作用
    前端学习02-01表格标签
    前端学习01-07图像地图
  • 原文地址:https://www.cnblogs.com/zhihou/p/8939990.html
Copyright © 2020-2023  润新知