• node.js date-utils


    前端引用

    <script type="text/javascript" src="date-utils.min.js"></script>

    NODEJS服务端项目调用

    $ cnpm install date-utils
    require('date-utils');

    API :

    Static Methods 静态方法

    Date.today(); // 今天, 00:00:00
    Date.yesterday(); // 昨天, 00:00:00   
    Date.tomorrow(); // 明天, 00:00:00
    Date.validateDay(day, year, month); // true/false 否是有效的
    Date.validateYear(year); // true/false 一年之内是否有效

    Date.validateMonth(month); // true/false 一个月之内是否有效

    Date.validateHour(hour); // true/false 一个小时内是否有效

    Date.validateMinute(minute); // true/false 一分钟内是否有效

    Date.validateSecond(second); // true/false 一秒钟是否有效
    Date.validateMillisecond(millisecond); // true/false 一毫秒内是否有效
    Date.compare(date1, date2); // -1 如果要小于0,如果相等 如果要小于1

    Date.equals(date1, date2); // true/false 时间1和2是否相等

    Date.getDayNumberFromName(name); // su/sun/sunday - 0, mo/mon/monday - 1, etc
    Date.getMonthNumberFromName(name); // jan/january - 0, feb/february - 1, etc
    Date.isLeapYear(year); // true/false whether the year is a leap yearDate.get
    DaysInMonth(year, monthNumber); // 本月天数

    Instance Methods 接口方法

    d.clone(); // 返回一个新的日期对象集的副本 
    d.getMonthAbbr(); // 短流程的月份名称 , Jan, Feb, etc d.getMonthName(); // fill month name, January, February, etcd.getUTCOffset(); // returns the UTC offset d.getOrdinalNumber(); // day number of the year, 1-366 (leap year) d.clearTime(); // sets time to 00:00:00d.setTimeToNow(); // sets time to current time d.toFormat(format); // 返回日期格式 with:   // YYYY - Four digit year   // MMMM - Full month name. ie January   // MMM  - Short month name. ie Jan   // MM   - Zero padded month ie 01   // M    - Month ie 1   // DDDD - Full day or week name ie Tuesday    // DDD  - Abbreviated day of the week ie Tue   // DD   - Zero padded day ie 08   // D    - Day ie 8   // HH24 - Hours in 24 notation ie 18   // HH   - Padded Hours ie 06   // H    - Hours ie 6   // MI   - Padded Minutes   // SS   - Padded Seconds   // PP   - AM or PM   // P    - am or pmd.toYMD(separator); // returns YYYY-MM-DD by default, separator changes delimiter      d.between(date1, date2); // true/false if the date/time is between date1 and date2      d.compareTo(date); // -1 if date is smaller than this, 0 if equal, 1 if date is larger than thisd.equals(date); // true/false, true if dates are equal      d.isBefore(date); // true/false, true if this is before date passed      d.isAfter(date); // true/false, true if this is after date passed      d.getDaysBetween(date); // returns number of full days between this and passed      d.getHoursBetween(date); // returns number of hours days between this and passed      d.getMinutesBetween(date); // returns number of full minutes between this and passed      d.getSecondsBetween(date); // returns number of full seconds between this and passed      d.add({ milliseconds: 30,//计算问题         minutes: 1,         hours: 4,         seconds: 30,         days: 2,         weeks: 1,         months: 3,         years: 2}); // adds time to existing time                  d.addMilliseconds(number); // 添加到现有时间的毫秒数                  d.addSeconds(number); // 添加到现有时间秒                  d.addMinutes(number); // 添加几分钟到现有时间                  d.addHours(number); // add hours to existing time
    d.addDays(number); // add days to existing time                  d.addWeeks(number); // add weeks to existing time                  d.addMonths(number); // add months to existing timed.addYears(number); // add years to existing time                  d.remove(...); // same idea as for add//这里就是减法                  d.removeMilliseconds(number); // ...// same API, just remove instead

    静态调用必须要Date.today()

    动态方法 的 调用

    var today=new Date();

    today.add({});如此

    其中我还自己添加了两个方法 用于动态获取第几周的功能

    Date.prototype.getWeekOfYear = function() {//这天在本年是第几周
        var onejan = new Date(this.getFullYear(), 0, 1);
        return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
    };

    Date.prototype.getWeekOfMonth=function () {//这天在本月是第几周

        var day = this.getDate();

        //get weekend date
        day += (this.getDay() == 0 ? 0 : 7 - this.getDay());

        return Math.ceil(parseFloat(day) / 7);
    };

  • 相关阅读:
    js获取对象的最后一个
    vue UI框架
    从前端和后端两个角度分析jsonp跨域访问(完整实例)
    Ajax跨域访问解决方案
    js中将字符串转换成json的三种方式
    【转载】COM 组件设计与应用(九)——IDispatch 接口 for VC6.0
    【转载】COM 组件设计与应用(八)——实现多接口
    【转载】COM 组件设计与应用(七)——编译、注册、调用
    【转载】COM 组件设计与应用(六)——用 ATL 写第一个组件
    【转载】COM 组件设计与应用(五)——用 ATL 写第一个组件
  • 原文地址:https://www.cnblogs.com/GeneralKING/p/5635008.html
Copyright © 2020-2023  润新知