有没有一种方法可以使moment.js输出为"1天"?而不是“一天"? [英] Is there a way to make moment.js output "1 day" instead of "a day"?
本文介绍了有没有一种方法可以使moment.js输出为"1天"?而不是“一天"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I'm using the Time to X function of Moment.js. When the second parameter is true
, then the result is a day
. Is there a way to make this 1 day
through the API, or will I need to do a string replace?
推荐答案
您可以使用string.replace方法将"a day"
替换为"1 day"
.
You can use the string.replace method to replace "a day"
with "1 day"
.
或者您可以尝试以下操作:
Or you can try like this:
var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
var differenceInMillisec = a.diff(b);
var differenceInDays = a.diff(b, 'days'); //Output 1 day
这篇关于有没有一种方法可以使moment.js输出为"1天"?而不是“一天"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文