zhgdyunapp/static/js/util.js
2022-06-08 15:48:09 +08:00

35 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//获取前天-2昨天-1今天0明天1等时间 yyyy/MM/dd format,分隔符
export function GetDateStr(AddDayCount, format, from) {
var dd = !from ? new Date() : stringToDate(from,format);
dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期
var year = dd.getFullYear();
var month = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
var date = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
return year + format + month + format + date;
}
//将时间戳转换成日期格式
export function timestampToTime(timestamp,type) {
if(timestamp.length<13){
timestamp=timestamp*1000
}
        var date = new Date(timestamp);//时间戳为10位需*1000时间戳为13位的话不需乘1000
        let Y = date.getFullYear() + '-';
        let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        let D = date.getDate()<10?'0'+date.getDate():date.getDate();
        let h = ' '+date.getHours() + ':';
        let m = date.getMinutes() + ':';
        let s = date.getSeconds();
if(type=='date'){
return Y+M+D;
}else if(type=='time'){
return Y+M+D+h+m+s;
}
       
    }