1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/rainbond-rainbond-ui

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
date-util.js 3.4 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
xuzl Отправлено 3 лет назад fd7cc21
import { Modal } from 'antd';
import { formatMessage, FormattedMessage } from 'umi-plugin-locale';
const dateUtil = {
isWebSocketOpen(websocketURL) {
const protocolStr = document.location.protocol;
const str = websocketURL.substr(0, websocketURL.indexOf(':'));
if (protocolStr === 'https:' && str && str === 'ws') {
Modal.destroyAll();
Modal.error({
title: formatMessage({id:'utils.date_util.available'}),
content: (
<div>
{formatMessage({id:'utils.date_util.ws'})}
</div>
),
onOk() {}
});
return null;
}
return 'through';
},
format(date, format) {
let dates = new Date(date.replace(/\-/g, '/'));
if (dates == 'Invalid Date') {
dates = new Date(date);
}
const map = {
yyyy() {
return dates.getFullYear();
},
MM() {
const val = dates.getMonth() + 1;
return val < 10 ? `0${val}` : val;
},
dd() {
const val = dates.getDate();
return val < 10 ? `0${val}` : val;
},
hh() {
const val = dates.getHours();
return val < 10 ? `0${val}` : val;
},
mm() {
const val = dates.getMinutes();
return val < 10 ? `0${val}` : val;
},
ss() {
const val = dates.getSeconds();
return val < 10 ? `0${val}` : val;
}
};
for (const k in map) {
format = format.replace(k, map[k]);
}
return format;
},
/*
根据日期返回今天,昨天,前天,或者日期
*/
dateToCN(date, format) {
// 是否是今天
function isToday(str) {
let d = new Date(str.replace(/\-/g, '/'));
if (d == 'Invalid Date') {
d = new Date(str);
}
const todaysDate = new Date();
if (d.setHours(0, 0, 0, 0) == todaysDate.setHours(0, 0, 0, 0)) {
return true;
}
return false;
}
// 是否昨天
function isYestday(date) {
let d = new Date(date.replace(/\-/g, '/'));
if (d == 'Invalid Date') {
d = new Date(date);
}
const dates = new Date(); // 当前时间
const today = new Date(
dates.getFullYear(),
dates.getMonth(),
dates.getDate()
).getTime(); // 今天凌晨
const yestday = new Date(today - 24 * 3600 * 1000).getTime();
return d.getTime() < today && yestday <= d.getTime();
}
// 是否是前天
function isBeforeYestday(date) {
let d = new Date(date.replace(/\-/g, '/'));
if (d == 'Invalid Date') {
d = new Date(date);
}
const dates = new Date(); // 当前时间
const today = new Date(
dates.getFullYear(),
dates.getMonth(),
dates.getDate()
).getTime(); // 今天凌晨
const yestday = new Date(today - 24 * 3600 * 1000).getTime();
const beforeYestday = new Date(today - 48 * 3600 * 1000).getTime();
return d.getTime() < yestday && beforeYestday <= d.getTime();
}
function getShowData(date) {
if (isToday(date)) {
// return '今天';
return dateUtil.format(date, 'yyyy-MM-dd hh:mm:ss');
} else if (isYestday(date)) {
return `${formatMessage({id:'utils.date_util.yesterday'})}`;
} else if (isBeforeYestday(date)) {
return `${formatMessage({id:'utils.date_util.before_yesterday'})}`;
}
return dateUtil.format(date, format);
}
return getShowData(date);
}
};
export default dateUtil;

Комментарий ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/rainbond-rainbond-ui.git
git@gitlife.ru:oschina-mirror/rainbond-rainbond-ui.git
oschina-mirror
rainbond-rainbond-ui
rainbond-rainbond-ui
main