我想创建一个自定义语言环境并将其与DayJs一起使用。并且在文档中提到了该过程
但是,当我按照程序创建自己的语言环境时,我无法格式化之后的日期。
这是检查相同内容的JSFiddle。 https://jsfiddle.net/5o4pwbtc/
这是相同的GitHub问题:https ://github.com/iamkun/dayjs/issues/746
/* like mentioned here
https://github.com/iamkun/dayjs/blob/dev/docs/en/I18n.md#installation
*/
const locale = {
formats: {
// abbreviated format options allowing localization
LTS: 'h:mm:ss A',
LT: 'h:mm A',
L: 'MM/DD/YYYY',
LL: 'MMMM D, YYYY',
LLL: 'MMMM D, YYYY h:mm A',
LLLL: 'dddd, MMMM D, YYYY h:mm A',
// lowercase/short, optional formats for localization
l: 'D/M/YYYY',
ll: 'D MMM, YYYY',
lll: 'D MMM, YYYY h:mm A',
llll: 'ddd, MMM D, YYYY h:mm A'
},
relativeTime: {
name: 'en',
future: '%s',
past: '%s',
s: 'now',
m: 'a minute ago',
mm: '%d minutes ago',
h: 'an hour',
hh: '%d hours', // e.g. 2 hours, %d been replaced with 2
d: 'a day',
dd: '%d days',
M: 'a month',
MM: '%d months',
y: 'a year',
yy: '%d years'
}
}
dayjs.locale(locale);
dayjs(1575872723701).format()
// Uncaught TypeError: Cannot read property '10' of undefined
<script src="https://unpkg.com/dayjs@1.8.17/dayjs.min.js"></script>