react antd時間獲取,轉變時間差

 

例子創建在react框架之上;react

獲取時間;框架

時間:var time = new Date(); // Tue Aug 28 2018 09:16:06 GMT+0800 (中國標準時間);spa

時間戳:var timestamp = Date.parse(time); // 1535419062000 (Date.parse() 默認不取毫秒,即後三位毫秒爲0)code

 moment轉時間:moment(time).valueOf(); // 1535419062126orm

moment轉時間戳:moment(timestamp).format(); // 2018-08-28T09:17:42+08:00blog

 

獲取時間差;form

    let AA = "2019-01-09 18:15:00";
    let BB = "2019-01-07 17:15:00";
    let start_date = moment(AA,"YYYY-MM-DD HH:mm:ss");
    let end_date = moment(BB,"YYYY-MM-DD HH:mm:ss");
   let seconds
= end_date.diff(start_date,"seconds"); let mintus = (seconds/60); let hours = (mintus/60);
相關文章
相關標籤/搜索