moment.js 时间转换
import moment from 'moment';
import {ZERO_ONE} from '@/constants/constants';
const {ZERO, ONE} = ZERO_ONE;
const dateFormat = 'YYYY-MM-DD HH:mm:ss';
const transforMation = (list: any[]) => {
if (Array.isArray(list)) {
return list.map((item: moment.Moment, index: number) => {
if (index === ZERO) {
return moment(item).startOf('day').format(dateFormat);
} else if (index === ONE) {
return moment(item).endOf('day').format(dateFormat);
}
return item.format(dateFormat);
});
}
};
export default transforMation;
const getTimeDifference = (selectTion: any) => {
const copySeletion = _.cloneDeep(selectTion);
const startTime = copySeletion[0];
const endTime = copySeletion[1];
const timeDifference: number = endTime.diff(startTime, 'days');
const isMoreThanSeven: boolean = timeDifference > 7;
return {
isMoreThanSeven,
timeDifference,
};
};