moment获取几小时前_momentjs – 使用时刻在两个日期时间之间获得hh:mm的时差
我在獲取兩個(gè)時(shí)間戳(epoch格式)之間的時(shí)間差異方面存在問(wèn)題.
我使用moment().format(“L LT”)將其轉(zhuǎn)換為所需的日期時(shí)間格式(MM / DD / YYYY HH:MM(12小時(shí))),
但現(xiàn)在的問(wèn)題是,我希望hh:mm之間的時(shí)間差異
P.S.:它也可能超過(guò)24小時(shí).
我嘗試了什么:
let timeDiffms,duration,timedifference,
start moment(startTimeStampInMS).format("L LT"),
end = moment(endTimeStampInMS).format("L LT");
timeDiffms = moment(end, "MM/DD/YYYY HH:mm").diff(moment(start, "MM/DD/YYYY HH:mm"));
duration = moment.duration(timeDiffms);
timedifference = Math.floor(duration.asHours()) +":"+duration.minutes(); // result
//output I am getting
// start = "03/20/2017 3:11 PM" end="03/21/2017 9:45 AM" timedifference = "30:24", (incorrect)
// start = "03/20/2017 10:07 AM" end="03/23/2017 11:24 AM" timedifference = "73:17" (correct)
// start = "03/20/2017 3:11 PM" end="03/23/2017 11:31 AM" timedifference = "80:20" (incorrect) strange
我不知道這里發(fā)生了什么錯(cuò).
與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的moment获取几小时前_momentjs – 使用时刻在两个日期时间之间获得hh:mm的时差的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 动效引擎_汇众教育 | 高级引擎视效包装
- 下一篇: mpvue微信小程序动画_mpvue微信