This commit is contained in:
2020-07-06 17:32:29 +08:00
parent c6bea7a19a
commit 8dc45b57fd
15 changed files with 384 additions and 264 deletions

View File

@@ -9,26 +9,5 @@ const common = {
temp = "" + temp;
return temp.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&apos;/g, "'");
},
/**
* php时间戳转为格式化日期
* @param { String } timestamp 必填 php返回的时间戳
* @param { String } spacer 可选 日期间隔符,默认 '-'
* @param { String } end 可选 年月日时分秒截止位置,默认 day可传 second
* @return { String } 格式化日期
*/
timestampToDate({timestamp, spacer = '-', end = 'day'} = {}) {
if(!timestamp) return '';
const newDate = new Date(parseInt(timestamp) * 1000);
// const year = newDate.getUTCFullYear();
const year = newDate.getFullYear();
const month = newDate.getMonth() + 1;
const nowday = newDate.getDate();
const hours = newDate.getHours();
const minutes = newDate.getMinutes();
const seconds = newDate.getSeconds();
return end == 'day'
? year + spacer + month + spacer + nowday
: year + spacer + month + spacer + nowday + spacer + hours + spacer + minutes + spacer + seconds;
}
}
export default common