gpt4 book ai didi

javascript - MomentJS:使用默认字符串而不是自定义字符串

转载 作者:行者123 更新时间:2023-12-03 07:19:37 28 4
gpt4 key购买 nike

使用 moment.js 2.7,我想使用自定义字符串作为时间戳。我查看了文档,发现我只是做了这样的事情:

moment.lang('en', {
relativeTime: {
future: "the future",
past: "the past",
s: "soon",
m: "%d minute",
mm: "%d minutes",
h: "%d hour",
hh: "%d hours",
d: "%d day",
dd: "%d days",
M: 'never',
MM: 'never',
y: 'a long time',
yy: 'a long time'
}
});

但是,我想回到在代码的另一部分中使用默认字符串,并且想知道是否有一种快速方法将其设置回默认值,而不是像这样手动设置回默认值:

moment.lang('en', {
relativeTime: {
future: 'in %s',
past: '%s ago',
s: 'a few seconds',
m: 'a minute',
mm: '%d minutes',
h: 'an hour',
hh: '%d hours',
d: 'a day',
dd: '%d days',
M: 'a month',
MM: '%d months',
y: 'a year',
yy: '%d years'
}
});

最佳答案

你可以像这样定义自定义案例:

moment.lang('en-custom', {
relativeTime: {
future: "the future",
past: "the past",
s: "soon",
m: "%d minute",
mm: "%d minutes",
h: "%d hour",
hh: "%d hours",
d: "%d day",
dd: "%d days",
M: 'never',
MM: 'never',
y: 'a long time',
yy: 'a long time'
}
});

然后将其加载到需要的地方:

moment.lang("en-custom");

这样您就不会弄乱默认值。

关于javascript - MomentJS:使用默认字符串而不是自定义字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36266377/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com