如何在时刻时区重命名 preciseDiff 键?
How to Rename preciseDiff Key in moment-timezone?
如何在 moment-timezone
中重命名 preciseDiff
函数的键?
代码:
var duration = momentz.preciseDiff(0, 1528791845);
输出:
1 year 8 hours 17 minutes 6 seconds
我想将年、月和...翻译成另一种语言。
year año
month mes
day día
hour hora
minute minuto
second segundo
我想您必须手动替换它。也许另一个功能?
const es = {
year: 'año',
years: 'años',
month: 'mes',
day: 'día',
hour: 'hora',
hours: 'horas',
minute: 'minuto',
minutes: 'minutos',
second: 'segundo',
seconds: 'segundos'
};
const translateWords = (dictionary, string) => string
.split(' ')
.map(word=>dictionary[word]||word)
.join(' ');
const esString = translateWords(es, "1 year 8 hours 17 minutes 6 seconds");
console.log(esString); // 1 año 8 horas 17 minutos 6 segundos
如何在 moment-timezone
中重命名 preciseDiff
函数的键?
代码:
var duration = momentz.preciseDiff(0, 1528791845);
输出:
1 year 8 hours 17 minutes 6 seconds
我想将年、月和...翻译成另一种语言。
year año
month mes
day día
hour hora
minute minuto
second segundo
我想您必须手动替换它。也许另一个功能?
const es = {
year: 'año',
years: 'años',
month: 'mes',
day: 'día',
hour: 'hora',
hours: 'horas',
minute: 'minuto',
minutes: 'minutos',
second: 'segundo',
seconds: 'segundos'
};
const translateWords = (dictionary, string) => string
.split(' ')
.map(word=>dictionary[word]||word)
.join(' ');
const esString = translateWords(es, "1 year 8 hours 17 minutes 6 seconds");
console.log(esString); // 1 año 8 horas 17 minutos 6 segundos