简体   繁体   English

一天和几小时前的时刻

[英]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.

相关问题 Moment.js日前 - Moment.js Day Ago ReactJS:将日期转换为小时/分钟前或天/小时前 - ReactJS: convert date to a hours/minutes ago or day/hours ago 检查数据是否在 24 小时前或一天前更新(laravel) - Check if data updated_at 24 hours ago OR a day ago (laravel) ReactJS:将 EpochTime 从 1970 年到现在,1 小时前,2 小时前,1 天前,3 天前 - ReactJS: Convert EpochTime since 1970 to just now, 1 hour ago, 2 hours ago, 1 day ago, 3 days ago 如何将时刻js中的后缀从2小时前更改为2小时 - how to Change the suffix in moment js from 2 hours ago to 2h 12小时格式的一天的瞬间js间隔 - Moment js interval for a day in 12 hours format moment.calendar将今天显示为当天,而不是5天前 - moment.calendar shows today as the day instead of 5 days ago 我怎样才能获得显示“昨天”而不是“一天前”的时间? - How can I get moment to display "yesterday" and not "a day ago"? 如何使用 moment.js 将日期时间字符串转换为一分钟前/一天前/一个月前/一年前格式 - How do I convert a datetime string to a mins ago/day ago/month ago/ year ago format using moment.js 使用时刻js创建一个星期几和一天中几小时的数组? - Using moment js to create an array with days of the week and hours of the day?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM