我想现在就用dayjs替换一下momentjs。首先,我添加了依赖项:
"dayjs":"1.10.7"然后像这样导入dayjs:
import { Dayjs } from 'dayjs';使用以下代码片段获取月份开始:
const fullDateTimeFormat = 'YYYY-MM-DD HH:mm:ss:SSS';
const startOfCurrentMonth = Dayjs().startOf("month").format(fullDateTimeFormat);但是向我展示这个错误:
TypeError: (0 , _dayjs.Dayjs) is not a function
selectMonthListState
src/components/SelectData/index.js:112
109 | const days = getMonthDay(year, month);
110 | const prevMonthDays = getMonthDay(year, month-1);
111 | const startDateValue = `${moment(year + '-' + (month-count +1) + '-01').format(dateFormat)} 00:00:00:000`;
> 112 | const startOfCurrentMonth = Dayjs().startOf("month").format(fullDateTimeFormat);
| ^ 113 | const endDateValue = count ===1? `${moment(year + '-' + (month) + '-' + prevMonthDays).format(dateFormat)} 23:59:59:999`: `${moment(year + '-' + (month+1) + '-' + days).format(dateFormat)} 23:59:59:999`;
114 |
115 | setSelectDate([moment(startDateValue, rPickerFormat), moment(endDateValue, rPickerFormat)]);我应该怎么做才能解决这个问题?我是不是遗漏了什么?
发布于 2021-12-02 10:50:48
我是这样使用它的:
import dayjs from 'dayjs';
const startOfCurrentMonth = dayjs().startOf("month").format(fullDateTimeFormat);很管用。
https://stackoverflow.com/questions/70197895
复制相似问题