export const getCookie = (name) => {
if (process.SERVER_BUILD) return;
return Cookie.get(name);
};
export const getTime = (option) => {
var date = new Date();
var Year = date.getFullYear();
var Month = date.getMonth() + 1;
var Day = date.getDate();
switch (option) {
case 0:
return Year;
break;
case 1:
return Month;
break;
case 2:
return Day;
break;
}
};
export const getDate = (date, boolean) => {
var Year = date.getFullYear();
var Month = (date.getMonth() + 1 < 10 ? ‘0‘ + (date.getMonth() + 1) : date.getMonth() + 1);
var Day = date.getDate() < 10 ? ‘0‘ + date.getDate() : date.getDate();
if (boolean == true) {
var Hour = date.getHours() < 10 ? ‘0‘ + date.getHours() : date.getHours();
var Minute = date.getMinutes() < 10 ? ‘0‘ + date.getMinutes() : date.getMinutes();
var Second = date.getSeconds() < 10 ? ‘0‘ + date.getSeconds() : date.getSeconds();
return (Year + ‘-‘ + Month + ‘-‘ + Day + ‘ ‘ + Hour + ‘:‘ + Minute + ‘:‘ + Second)
} else {
return (Year + ‘-‘ + Month + ‘-‘ + Day)
}
};
/*根据日期字符串,返回Date对象,兼容safari*/
export const returnDate = (dateTimeString) => {
if (typeof(dateTimeString) != "string") {
return new Date(dateTimeString)
}
var datetime;
if (isNaN(Date.parse(dateTimeString))) {
datetime = new Date(Date.parse(dateTimeString.replace(/-/g, ‘/‘).replace(/T/g, ‘‘)));
} else {
datetime = new Date(Date.parse(dateTimeString))
}
return datetime
};
export const getYesterday = (time) => {
var date = time || new Date(),
timestamp,
newDate;
if (!(date instanceof Date)) {
date = new Date(date.replace(/-/g, ‘/‘));
}
timestamp = date.getTime();
newDate = new Date(timestamp - 1 * 24 * 3600 * 1000);
return [newDate.getFullYear(), newDate.getMonth() + 1, newDate.getDate()].join(‘-‘);
};
export const getSevenDaysBefore = (time) => {
var date = time || new Date(),
timestamp,
newDate;
if (!(date instanceof Date)) {
date = new Date(date.replace(/-/g, ‘/‘));
}
timestamp = date.getTime();
newDate = new Date(timestamp - 7 * 24 * 3600 * 1000);
return [newDate.getFullYear(), newDate.getMonth() + 1, newDate.getDate()].join(‘-‘);
}
export const browserType = (from) => {
var explorer = from.toLowerCase();
//ie
var isIe8 = false;
if (explorer.indexOf("msie") >= 0) {
var ver = explorer.match(/msie ([\d.]+)/)[1];
if (ver <= ‘9.0‘) {
isIe8 = true;
}
}
return isIe8;
};