Skip to content

Instantly share code, notes, and snippets.

@Duobe
Created August 15, 2017 08:06
Show Gist options
  • Save Duobe/c7b314c6375512fefe92eb0dccb95e74 to your computer and use it in GitHub Desktop.
Save Duobe/c7b314c6375512fefe92eb0dccb95e74 to your computer and use it in GitHub Desktop.
时间计算
getTimeByYearAndMonth = () => {
// month start with 0
// 获取某日开始时间、结束时间
const firstTimeOfDay = new Date(year, month, date);
const lastTimeOfDay = new Date(new Date(year, month, date + 1) - 1);
// 获取某月开始第一天时间、月最后一天时间
const firstDayOfMonth = new Date(year, month, 1);
const lastDayOfMonth = new Date(new Date(year, month + 1, 1) - 1);
// 获取某年开始第一天时间、最后一天时间 [即1月开始的一天00:00:00、12月最后一天23:59:59]
const firstDayOfYear = new Date(year, month, 1);
const lastDayOfYear = new Date(new Date(year, month) - 1);
return { firstDayOfMonth, lastDayOfMonth, firstDayOfYear, lastDayOfYear }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment