码迷,mamicode.com
首页 > Web开发 > 详细

js获取当月最后一天

时间:2018-09-18 19:10:17      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:tps   question   .com   blank   文章   col   alt   ast   str   

构造函数

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

 

js获取当月最后一天

标签:tps   question   .com   blank   文章   col   alt   ast   str   

原文地址:https://www.cnblogs.com/yeminglong/p/9670192.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!