js獲取當月最後一天
阿新 • • 發佈:2018-09-18
script https bsp minute 小時 ron 開始 minutes 表示
day 代表一個月中的第幾天的整數值,從1開始。
hour 代表一天中的小時數的整數值 (24小時制)。
minute 分鐘數。
second 秒數。
millisecond 表示時間的毫秒部分的整數值
構造函數
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獲取當月最後一天