4
我使用moment.js之間的差異不正確,我用下面的代碼做出反應器應用找到2 UNIX之間的區別時間戳:Moment.js給予2個日期
import Moment from 'moment';
Moment.duration(
Moment(this.state.saleEndTime).diff(Moment(this.state.saleStartTime))
).humanize()
其中
this.state.saleStartTime
是1511638810
(週六,2017年11月25日十九時40分10秒GMT)this.state.saleEndTime
是1516909110
(星期四,2018年1月25日十九點38分30秒GMT)
但是它給輸出
an hour
這顯然是不正確的,它應該是2個月。我做錯了什麼?
使用時刻v2.19.2與節點V7.9.0
編輯:需要將輸出humanize
「版,並this.state.saleStartTime
和this.state.saleEndTime
之間的時間差可以從幾分鐘到幾個月...
你不應該傳遞一個單元[DIFF](https://momentjs.com/docs /#/顯示/差值/)? –
[獲得Moment Js中兩個日期之間的差異時間差異](https://stackoverflow.com/questions/25150570/get-hours-difference-between-two-dates-in-moment-js) – TheMintyMate
@ Sag1v如果2個unix時間戳可以相距幾分鐘或幾個月,那麼我應該通過單元,並且輸出應該是「人性化」的? – Nyxynyx