// 金额转化 2001=>20.01 const conversion = (num : number) => { let str = (num / 100).toFixed(2) + ''; let intSum = str.substring(0, str.indexOf('.')).replace(/\B(?=(?:\d{3})+$)/g, ',');//取到整数部分 let dot = str.substring(str.length, str.indexOf('.'));//取到小数部分搜索 let ret = intSum + dot; return ret; }; const getMonthTimestamps = (month : string) => { //解析月份字符串 const [yearstr, monthStr] = month.split('-'); const year = parseInt(yearstr); const monthIndex = parseInt(monthStr) - 1; // 月份从 开始计数,所以需 //获取该月份开始的时间戳 const startofMonth = new Date(year, monthIndex, 1).getTime(); // 获取下个月份开始的时间戳 const nextMonth = monthIndex === 11 ? 0 : monthIndex + 1; const nextYear = monthIndex === 11 ? year + 1 : year; const startofNextMonth = new Date(nextYear, nextMonth, 1).getTime(); return [ startofMonth, startofNextMonth ] } function timestampToDatetime(timestamp : number, format = 'YYYY-MM-DD hh:mm:ss') { if(timestamp == 0) { return '-' } // 创建一个新的Date对象,使用传入的时间戳作为参数 const date = new Date(timestamp); // 获取年、月、日、时、分、秒 const year = date.getFullYear(); const month = ('0' + (date.getMonth() + 1)).slice(-2); // 月份是从0开始的,所以要加1 const day = ('0' + date.getDate()).slice(-2); const hours = ('0' + date.getHours()).slice(-2); const minutes = ('0' + date.getMinutes()).slice(-2); const seconds = ('0' + date.getSeconds()).slice(-2); if (format == 'YYYY-MM-DD') { return year + '-' + month + '-' + day } // 返回格式化后的时间字符串 return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds; } function getWxMiniProgramUrlParam(url) { let theRequest = {}; if (url.indexOf("#") != -1) { const str = url.split("#")[1]; const strs = str.split("&"); for (let i = 0; i < strs.length; i++) { theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]); } } else if (url.indexOf("?") != -1) { const str = url.split("?")[1]; const strs = str.split("&"); for (let i = 0; i < strs.length; i++) { theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]); } } return theRequest; } export { conversion, getMonthTimestamps, timestampToDatetime, getWxMiniProgramUrlParam }