函數目錄
?? getFormatDateStr 獲得指定日期格式的字符串;
?? getDayPrevAfter 獲得n天前/后的日期;
?? formatDateWithTimeZone 格式化日期帶時區,ISO 8601;
?? countDownBySecond 倒計時;
?? monthSize 獲得指定日期所在月的天數;
?? getCalendarMonth 獲得指定日期所在月的第一周到第四/五周的數據組合;
?? getOneDateWeekIndex 獲得指定的某天所在該月的第幾周,下標從0開始;
下面是詳細的說明:
monthSize
/**
* [monthSize 獲得指定日期所在月的天數]
* @param? {[Date]} oDate [指定的日期,非必填,默認為當天]
* @return {[Int]}? ? ? [總天數]
*/
function monthSize(oDate) {
oDate = oDate ? oDate : new Date();
let year = oDate.getFullYear(),
month = oDate.getMonth(),
_oDate = new Date();
_oDate.setFullYear(year);
_oDate.setMonth(month + 1, 0);
return _oDate.getDate();
}
getOneDateWeekIndex
/**
* [getOneDateWeekIndex 獲得指定的某天所在該月的第幾周,下標從0開始]
* @param? {[Date]} date [指定的日期,非必填,默認為當天]
* @return {[Int]}? ? ? [在該月的第幾周]
*/
export function getOneDateWeekIndex(date) {
date = date ? date : new Date();
let monthDays = getCalendarMonth(date);
let dateString = getFormatDateStr(date, '/', true, false, false);
let returnDate = monthDays.filter(item => {
return item.date === dateString;
});
let weekIndex = returnDate[0].weekIndex;
return weekIndex ? weekIndex : 0;
}