getTime(val) {
let datenow = new Date()
let nowDay = datenow.getDate() //当前日
let nowMonth = datenow.getMonth() //当前月
let nowYear = datenow.getFullYear() //当前年
let nowDayOfWeek = datenow.getDay() //今天本周的第几天
let jd = Math.ceil((nowMonth + 1) / 3)
let startTime = ''
let endTime = ''
if (val == '今天') {
//今天
startTime = new Date(nowYear, nowMonth, nowDay)
endTime = new Date(
nowYear,
nowMonth,
nowDay,
23,
59
)
} else if (val == '昨天') {
//昨天
startTime = new Date(
nowYear,
nowMonth,
nowDay - 1
)
endTime = new Date(
nowYear,
nowMonth,
nowDay - 1,
23,
59
)
} else if (val == '本周') {
//本周
startTime = new Date(
nowYear,
nowMonth,
nowDay - nowDayOfWeek + 1
)
endTime = new Date(
nowYear,
nowMonth,
nowDay + (7 - nowDayOfWeek)
)
} else if (val == '上周') {
//上周
let day = datenow.getDay() == 0 ? 7 : datenow.getDay()
startTime = new Date(
nowYear,
nowMonth,
nowDay - 6 - day
)
endTime = new Date(
nowYear,
nowMonth,
nowDay - day
)
} else if (val == '本月') {
//本月
startTime = new Date(nowYear, nowMonth, 1)
endTime = new Date(nowYear, nowMonth + 1, 0)
} else if (val == '上月') {
//上月
startTime = new Date(nowYear, nowMonth - 1, 1)
endTime = new Date(
nowYear,
nowMonth,
nowDay - nowDay
)
} else if (val == '本季度') {
//本季度
startTime = new Date(nowYear, (jd - 1) * 3, 1)
endTime = new Date(nowYear, jd * 3, 0)
} else if (val == '上季度') {
//上季度
startTime = new Date(
nowYear,
(jd - 1) * 3 - 3,
1
)
endTime = new Date(nowYear, jd * 3 - 3, 0)
} else if (val == '今年') {
//今年
startTime = new Date(nowYear, 0, 1)
endTime = new Date(nowYear, 11, 31)
}
return {
startTime,
endTime
}
}
js 获取今天/昨天/本周/上周/本月/上月/本季度/上季度/今年的时间
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 因为日期选择器使用的地方较多,放在 mixins 里面使用比较方便; 正常日期范围也一样,就是把数据放出来即可; ...
- <?php /**date 2021-09-10 * author /www.mahu.net.cn ...
- 开发过程中,常用日期处理函数,时间戳处理函数等,如下讲解: (年月日时分秒,“-”间隔):2017-11-04 1...