【发布时间】:2021-09-17 16:13:58
【问题描述】:
这是我的代码快照以了解更多详细信息:
index.js
import moment from 'moment'
moment.updateLocale('en', {
relativeTime: {
future: 'in %s',
past: '%s ago',
s: '%ds',
m: '%dm',
mm: '%dm',
h: '%dh',
hh: '%dh',
d: '%dd',
dd: '%dd',
M: '%d month',
MM: '%d months',
y: '%d year',
yy: '%d years'
}
})
function format ({ duration }) {
// How to return below output from date-fns module?
return moment.duration(duration).humanize()
}
console.log(format(60000))// output is --> 10m
cmd> node index.js
我想通过 date-fns local 做同样的事情。但我没有看到任何 updateLocale 方法,也不知道如何进行映射。我在 moment.updateLocale({}) 对象中所做的。
【问题讨论】:
标签: javascript momentjs javascript-objects moment-timezone date-fns