bei*_*ogi 9 javascript momentjs dayjs
我有两个时间输入,我想使用 dayjs 获取这两个时间之间的差异/时间间隔
fromtime = '13:00'
totime = '17:00'
Run Code Online (Sandbox Code Playgroud)
所以上面两个的输出应该是4:00小时
我试过
fromtime = '13:00'
totime = '17:00'
Run Code Online (Sandbox Code Playgroud)
但我没有得到预期的输出。
我找到了解决这个问题的方法。
const fromtime = '11:20'
const totime = '12:30'
const ft = dayjs(`2000-01-01 ${fromtime}`);
const tt = dayjs(`2000-01-01 ${totime}`);
const mins = tt.diff(ft, "minutes", true);
const totalHours = parseInt(mins / 60);
const totalMins = dayjs().minute(mins).$m
Run Code Online (Sandbox Code Playgroud)
这将给出输出为totalHours = 1和totalMins = 10。
希望这对某人有帮助。