zoukankan      html  css  js  c++  java
  • jQuery日期插件

    jQuery.dateCollections = (function(){
    
        var nowDate = new Date();
        var cloneNowDate = new Date();
    
        var fullYear = nowDate.getFullYear();
        var month = nowDate.getMonth() + 1; // getMonth 方法返回 0-11,代表1-12月
        var date = nowDate.getDate();
    
        var endOfMonth = new Date(fullYear, month, 0).getDate(); // 获取本月最后一天
    
        // 格式化日期 (2016-02-14)
        function getFullDate(targetDate) {
            var D, y, m, d;
            if (targetDate) {
                D = new Date(targetDate);
                y = D.getFullYear();
                m = D.getMonth() + 1;
                d = D.getDate();
            } else {
                y = fullYear;
                m = month;
                d = date;
            }
            m = m > 9 ? m : '0' + m;
            d = d > 9 ? d : '0' + d;
    
            return y + '-' + m + '-' + d;
        }
    
        // 一天的时间戳(毫秒为单位)
        var timestampOfDay = 1000*60*60*24;
    
        // 今天,昨天
        var fullToday = getFullDate();
        var fullYesterday = getFullDate(nowDate - timestampOfDay);
    
        var nowDay = nowDate.getDay(); // getDay 方法返回0 表示星期天
        nowDay = nowDay === 0 ? 7 : nowDay;
    
        // 本周一,本周末(星期天)
        // 注:在safari下(nowDate +- 0)不会转换为时间戳,这里在nowDate前加上运算符+,手动转换时间戳运算
        var fullMonday = getFullDate( +nowDate - (nowDay-1)*timestampOfDay );
        var fullSunday = getFullDate( +nowDate + (7-nowDay)*timestampOfDay );
    
        // 月初,月末
        var fullStartOfMonth = getFullDate( cloneNowDate.setDate(1) );
        var fullEndOfMonth = getFullDate( cloneNowDate.setDate(endOfMonth) );
    
        return {
            fullToday: fullToday,
            fullYesterday: fullYesterday,
            fullMonday: fullMonday,
            fullSunday: fullSunday,
            fullStartOfMonth: fullStartOfMonth,
            fullEndOfMonth: fullEndOfMonth
        };
    
    }());

    转博客园(杨君华的博客)

  • 相关阅读:
    poj4474 Scout YYF I(概率dp+矩阵快速幂)
    网络编程之TCP异步群聊:服务器端代码
    平衡树(AVL)详解
    网络编程之TCP异步群聊:客户端代码
    [置顶] android 图片库的封装
    oracle的nvl函数的使用解析
    七天美音英标学习总结
    软考(7)——看图心想 标准化和知识产权
    Node.js学习(7)----包
    Ubuntu bitnami gitlab 安装
  • 原文地址:https://www.cnblogs.com/wenb/p/6723382.html
Copyright © 2011-2022 走看看