1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- // 获取本月开始日期和结束日期
- export const GetMonthDate = () => {
- let monthDate = {};
- let now = new Date(); //当前日期
- let nowMonth = now.getMonth(); //当前月
- let nowYear = now.getFullYear(); //当前年
- //本月的开始时间
- let monthStartDate = new Date(nowYear, nowMonth, 1);
- let yy = monthStartDate.getFullYear() + '-';
- let mm =
- (monthStartDate.getMonth() + 1 < 10
- ? '0' + (monthStartDate.getMonth() + 1)
- : monthStartDate.getMonth() + 1) + '-';
- let dd =
- monthStartDate.getDate() < 10
- ? '0' + monthStartDate.getDate()
- : monthStartDate.getDate();
- //本月的结束时间
- let monthEndDate = new Date(nowYear, nowMonth + 1, 0);
- let YY = monthEndDate.getFullYear() + '-';
- let MM =
- (monthEndDate.getMonth() + 1 < 10
- ? '0' + (monthEndDate.getMonth() + 1)
- : monthEndDate.getMonth() + 1) + '-';
- let DD =
- monthEndDate.getDate() < 10
- ? '0' + monthEndDate.getDate()
- : monthEndDate.getDate();
- monthDate.startDateString = yy + mm + dd;
- monthDate.endDateString = YY + MM + DD;
- monthDate.startDateTime = yy + mm + dd + ' 00:00:00';
- monthDate.endDateTime = YY + MM + DD + ' 23:59:59';
- monthDate.startDate = new Date(monthDate.startDateString);
- monthDate.endDate = new Date(monthDate.endDateString);
- return monthDate;
- };
- // Date转换为String
- // 参数:date:传入日期
- export const GetDateString = (date) => {
- let year = date.getFullYear().toString();
- let month = (date.getMonth() + 1 < 10
- ? '0' + (date.getMonth() + 1)
- : date.getMonth() + 1
- ).toString();
- let day = (date.getDate() < 10
- ? '0' + date.getDate()
- : date.getDate()
- ).toString();
- let hour = date.getHours().toString();
- let minute = date.getMinutes().toString();
- return year + '-' + month + '-' + day;
- };
|