目次
Get a list of dates for the target year and month
Get a list of dates by specifying the year and month as arguments.
/**
* 対象年月の日付一覧を取得
* @param year
* @param month
* @returns 対象年月の日付一覧
*/
export const getAllDays = (year: number, month: number): Date[] => {
const date = new Date(year, month, 1)
const dates = []
while (date.getMonth() === month) {
dates.push(new Date(date))
date.setDate(date.getDate() + 1)
}
return dates
}
Get the day of the week for the target date
Get the day of the week by passing Date as an argument.
/**
* 対象日の曜日を取得
* @param date
* @returns 対象日の曜日
*/
export const getDayOfWeek = (date: Date): string => {
const day = date.getDay()
const weekItems = ['日', '月', '火', '水', '木', '金', '土']
return weekItems[day]
}