【发布时间】:2022-12-07 18:37:24
【问题描述】:
我在我的 google chrome 控制台中遇到了一些问题,我收到了 Uncaught TypeError: c.diff is not a function,而在我的 vscode 中,当我将鼠标悬停在我的代码中时,我收到了 'diff' 在 'Date' 中不存在。但是当我在其他代码编辑器的代码示例中测试我的代码时,我收到了预期的输出。这是将 moment 转化为 luxon 的过程。这是代码示例:https://stackblitz.com/edit/js-nw6ctg?file=index.js。但我在这里导入了 luxon:
import * as luxon from 'luxon';
这是我的代码示例,我将其悬停在 vscode 中并给出错误:
const checkInLuxon5K = DateTime.now().startOf('day').set({ hour: 14 });
const checkOutLuxon5K = DateTime.now()
.startOf('day')
.plus({ days: 2 })
.set({ hour: 11 });
const checkIn = DateTime.fromISO(checkInString, { zone: 'Europe/Spain' }).toJSDate();
const checkOut = DateTime.fromISO(checkOutString, { zone: 'Europe/Spain' }).toJSDate();
const totalDuration = Duration.fromMillis((checkOut).diff(checkIn)).as('minutes');
const currentDuration = Duration.fromMillis((checkIn).diff(DateTime.now())).as('minutes');
Output: Error: checkIn.diff is not a function
【问题讨论】:
标签: javascript reactjs typescript momentjs luxon