moment获取几小时前_momentjs – 使用时刻在两个日期时间之间获得hh:mm的时差
我在獲取兩個時間戳(epoch格式)之間的時間差異方面存在問題.
我使用moment().format(“L LT”)將其轉換為所需的日期時間格式(MM / DD / YYYY HH:MM(12小時)),
但現在的問題是,我希望hh:mm之間的時間差異
P.S.:它也可能超過24小時.
我嘗試了什么:
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
我不知道這里發生了什么錯.
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的moment获取几小时前_momentjs – 使用时刻在两个日期时间之间获得hh:mm的时差的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 动效引擎_汇众教育 | 高级引擎视效包装
- 下一篇: mpvue微信小程序动画_mpvue微信