utils.js 473 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import moment from 'moment';

export const switchTimeToPeriod = (time) => {
  if (!time) return '';
  let _day = 0;
  let _hour = 0;
  let _minutes = 0;
  _day = moment().diff(moment(time), 'days');
  _hour = moment().diff(moment(time), 'hours');
  _minutes = moment().diff(moment(time), 'minutes');

  return (
    `${_day ? _day + '天' : ''}${_hour ? _hour - _day * 24 + '小时' : ''}${
      _minutes ? _minutes - _hour * 60 + '分钟' : ''
    }` || '刚刚'
  );
};