简体   繁体   English

如何在moment-timezone中重命名precisionDiff键?

[英]How to Rename preciseDiff Key in moment-timezone?

How to Rename key of preciseDiff Function in moment-timezone ? 如何在moment-timezone重命名preciseDiff函数的键?

code: 码:

var duration = momentz.preciseDiff(0, 1528791845);

output: 输出:

1 year 8 hours 17 minutes 6 seconds

I will want to translate year, month and ... to another language. 我想将年,月和...翻译成另一种语言。

year       año  
month      mes  
day        día  
hour       hora  
minute     minuto  
second     segundo  

I would imagine you would have to replace it manually. 我想您将不得不手动更换它。 Maybe another function? 也许另一个功能?

 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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM