zoukankan      html  css  js  c++  java
  • JQuery/JS插件 日期插件

    用于日期的计算,功能比较全,我常用的主要是日期的计算(多一天少一天,或者添加几个月等),日期格式化

    网址:http://momentjs.cn/

    测试代码:

    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <meta charset="utf-8" />
    </head>
    <body>
        <script type="text/javascript" src="http://momentjs.cn/downloads/moment.js"></script>
        <script type="text/javascript">
    
            var d1 = moment('2019-01-29 14:27:00').add(1, 'minutes').format("YYYY-MM-DD HH:mm:ss");
            var d2 = moment('2019-01-29 14:27:00').add(1, 'hours').format("YYYY-MM-DD HH:mm:ss");
            var d3 = moment('2019-01-29 14:27:00').add(1, 'days').format("YYYY-MM-DD HH:mm:ss");
            var d4 = moment('2019-01-29 14:27:00').add(1, 'months').format("YYYY-MM-DD HH:mm:ss");
            //var d5 = moment('2019-01-29 14:27:00').add(-1, 'minutes').format("YYYY-MM-DD HH:mm:ss");
            //console.log(d5);
    
    
            //改变时间
            var changeTime = function (timeType, timeNumber) {
    
                var WaringTime = '2019-01-29 14:27:00';
                console.log(WaringTime);
    
                //var waringDate = new Date(WaringTime);
                var strStartTime = null;
                var strEndTime = null;
    
                var type = '';
                if (timeType == '分钟') {
                    type = 'minutes';
                } else if (timeType == '小时') {
                    type = 'hours';
                }
                else if (timeType == '') {
                    type = 'days';
                }
                else if (timeType == '') {
                    type = 'months';
                }
                strStartTime = moment(WaringTime).add(-timeNumber, type).format("YYYY-MM-DD HH:mm:ss");
                strEndTime = moment(WaringTime).add(timeNumber, type).format("YYYY-MM-DD HH:mm:ss");
    
                console.log(strStartTime);
                console.log(strEndTime);
    
                //$("#StartTime").val(strStartTime);
                //$("#EndTime").val(strEndTime);
            }
    
            changeTime('', 1);
    
        </script>
    </body>
    </html>
  • 相关阅读:
    ...
    RUP,XP,敏捷原理
    JSP的内置对象——SESSION
    JSP的内置对象——REQUEST
    节点属性
    RUP,XP,敏捷原理
    寄存器
    设置背景图片
    Java代码空格问题
    数据库常见错误
  • 原文地址:https://www.cnblogs.com/guxingy/p/11125383.html
Copyright © 2011-2022 走看看