对搜索时间框内的处理

1.效果

 

2.js

 /**
     * yyyy-MM--dd
     * */
    getNowFormatDate: function () {
        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;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    },
    /**
     * yyyy-MM-dd HH:mm:ss
     */
    getNowFormatDate2: function () {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        //外国的月份都是从0开始的,所以+1
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        var hours = date.getHours();
        var minutes = date.getMinutes();
        var seconds = date.getSeconds();
        //1-9月用0补位
        if(month >=1 && month <=9){
            month = "0" + month;
        }
        //1-9日用0补位
        if(strDate >=0 && strDate <= 9){
            strDate = "0" + strDate;
        }
        //1-9日用0补位
        if(hours >=0 && hours <= 9){
            hours = "0" + hours;
        }
        //1-9日用0补位
        if(minutes >=0 && minutes <= 9){
            minutes = "0" + minutes;
        }
        //1-9日用0补位
        if(seconds >=0 && seconds <= 9){
            seconds = "0" + seconds;
        }
        //获取当前时间 yyyy-MM-dd HH:mm:ss
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + "23" + seperator2 + "59" + seperator2 + "59";
        return currentdate;
    },

    /**
     * yyyy-MM-dd HH:mm:ss
     */
    getNowFormatDate3: function () {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        //外国的月份都是从0开始的,所以+1
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        //1-9月用0补位
        if(month >=1 && month <=9){
            month = "0" + month;
        }
        //1-9日用0补位
        if(strDate >=0 && strDate <= 9){
            strDate = "0" + strDate;
        }
        //获取当前时间 yyyy-MM-dd HH:mm:ss
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " +"00" + seperator2 + "00" + seperator2 + "00";
        return currentdate;
    }

3.controller

try {
            if (StringUtils.isNotBlank(beginTimestamp)) {
                //开始时间要做成 2019-02-16 00:00:00的格式
                beginTimestamp = TimeUtil.toTimestamp10(beginTimestamp + " " + "00:00:00");
            }
            if (StringUtils.isNotBlank(endTimestamp)) {
                //结束时间要做成 2019-02-16 23:59:59的格式
                endTimestamp = TimeUtil.toTimestamp10(endTimestamp + " " + "23:59:59");
            }

4.TimeUtil

 /**
     * 时间显示转10位时间戳(yyyy-MM-dd HH:mm:ss)
     * @return
     */
    public static String toTimestamp10(String date) throws ParseException {
       return String.valueOf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date).getTime()).substring(0,10);
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值