zoukankan      html  css  js  c++  java
  • js获取当月最后一天

    构造函数

    new Date();
    new Date(value);
    new Date(dateString);
    new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);

    各参数的含义:

    value 代表自1970年1月1日00:00:00 (世界标准时间) 起经过的毫秒数。
    dateString 表示日期的字符串值。该字符串应该能被 Date.parse() 方法识别
    year 代表年份的整数值。为了避免2000年问题最好指定4位数的年份; 使用 1998, 而不要用 98.
    month 代表月份的整数值从0(1月)到11(12月)。
    day 代表一个月中的第几天的整数值,从1开始。
    hour 代表一天中的小时数的整数值 (24小时制)。
    minute 分钟数。
    second 秒数。
    millisecond 表示时间的毫秒部分的整数值

    当月第一天和最后一天

     

    可直接用年月日构造一个日期:

    var date = new Date(), y = date.getFullYear(), m = date.getMonth();
    var firstDay = new Date(y, m, 1);
    var lastDay = new Date(y, m + 1, 0);

     

    var date = new Date();
    var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
    var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);

    指定月份的第一天和最后一天

    比如2012年1月第一天和最后一天,运算时月份要减1

    var y = 2012, m = 1
    var firstDay = new Date(y, m - 1, 1);
    var lastDay = new Date(y, m, 0);
    console.log(firstDay);
    console.log(lastDay);

     参考地址:https://stackoverflow.com/questions/13571700/get-first-and-last-date-of-current-month-with-javascript-or-jquery?utm_source=ourjs.com

    如果这篇文章对您有帮助,您可以打赏我

    技术交流QQ群:15129679

  • 相关阅读:
    【关键字】
    【选择结构语句:switch】
    【数据类型】
    【接口】
    【抽象类和接口的区别】
    【访问权限】
    【内部类】
    【方法】
    【this 关键字】
    【Static】
  • 原文地址:https://www.cnblogs.com/yeminglong/p/9670192.html
Copyright © 2011-2022 走看看