如何在时刻时区中重命名 precisionDiff 键?

赛义德·海达里扎雷

如何重命名preciseDiff函数中的moment-timezone

代码:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章