Last active
January 26, 2021 17:35
-
-
Save Nukeer/986917c77c11f4f56da683df48343bfc to your computer and use it in GitHub Desktop.
get array of days in month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getYear } from 'date-fns'; | |
getDaysInMonth(month): Array<number> { | |
const date = new Date(getYear(new Date()), month, 1); | |
const days = []; | |
while (date.getMonth() === month) { | |
days.push({ name: new Date(date).getDate() }); | |
date.setDate(date.getDate() + 1); | |
} | |
return days; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment