xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js 计算时间差 All In One

js 计算时间差 All In One

dayjs 计算时间差

const old = '2019-12-22'
const now = '2021-12-22'

const days = now - old;
// ?


const old = dayjs('2019-12-22')
const now = dayjs('2021-12-22');

const days = now.diff(old, 'day');
// 731

now.diff(dayjs('2020-12-22'), 'day');
// 365

refs

https://day.js.org/docs/zh-CN/durations/durations

https://day.js.org/docs/zh-CN/display/difference#docsNav



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-12-22 11:23  xgqfrms  阅读(48)  评论(4编辑  收藏  举报