[英]moment a day and hours ago
I have these dates我有这些日期
promoEnd = ISODate("2020-10-20T10:00:00.000Z") Today is 2020-09-28T01:00:00.000Z") promoEnd = ISODate("2020-10-20T10:00:00.000Z") 今天是 2020-09-28T01:00:00.000Z")
If I use如果我使用
moment.duration(now.diff(promoEnd)).humanize()
My result is 21 days.我的结果是21天。
How Can I have 21 days and X hours in the same result?我怎么能在相同的结果中有 21 天和 X 小时? I need even to vice-versa, 21 days and 10 hours ago, for example例如,在 21 天 10 小时前,我什至需要反之亦然
It does not seem like you need to use humanize if you want some specific output, you could probably do something like:如果您想要一些特定的输出,似乎不需要使用 humanize,您可能会执行以下操作:
const duration = moment.duration(now.diff(promoEnd));
const result = `${duration.days()} days and ${duration.hours()} hours`;
Note that it could be weird for zero days / hours/请注意,零天/小时/可能会很奇怪
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.