1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- export function dateFormat(date, format = 'YYYY-MM-DD HH:mm:ss') {
- const config = {
- YYYY: date.getFullYear(),
- MM: date.getMonth() < 9 ? '0' + Number(date.getMonth() + 1) : Number(date.getMonth() + 1),
- DD: date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
- HH: date.getHours() < 10 ? '0' + date.getHours() : date.getHours(),
- mm: date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(),
- ss: date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds(),
- }
- for (const key in config) {
- format = format.replace(key, config[key])
- }
- return format
- }
- // 获取当月最后一天
- export function onthelastDay(date,onthelast, format = 'YYYY-MM-DD HH:mm:ss') {
- let config = {}
- config.YYYY = date.getFullYear()
- config.MM = date.getMonth()
- config.HH = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
- config.mm = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
- config.ss = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
- // 获取下个月的第一天
- const nextMonth = new Date(config.YYYY, config.MM + 1, 1);
- // 获取当前月的最后一天
- const lastDay = new Date(nextMonth.getTime() - 86400000);
- config.DD = lastDay.getDate() < 10 ? '0' + lastDay.getDate() : lastDay.getDate()
- config.MM = config.MM + 1 < 10 ? '0' + (config.MM + 1):config.MM + 1
- for (const key in config) {
- format = format.replace(key, config[key])
- }
- return format
- }
- export function unitConvert(num) {
- var moneyUnits = ["元", "万元", "亿元", "万亿"]
- var dividend = 10000;
- var curentNum = Number(num);
- //转换数字
- var curentUnit = moneyUnits[0];
- //转换单位
- for (var i = 0; i < 4; i++) {
- curentUnit = moneyUnits[i]
- if (strNumSize(curentNum) < 5) {
- break;
- }
- curentNum = curentNum / dividend
- }
- var m = {
- num: 0,
- unit: ""
- }
- m.num = curentNum.toFixed(2)
- m.unit = curentUnit;
- return m;
- }
- export function DX(n) {
- if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
- return "数据非法";
- var unit = "千百拾亿千百拾万千百拾元角分",
- str = "";
- n += "00";
- var p = n.indexOf('.');
- if (p >= 0)
- n = n.substring(0, p) + n.substr(p + 1, 2);
- unit = unit.substr(unit.length - n.length);
- for (var i = 0; i < n.length; i++)
- str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
- return str.replace(/零(千|百|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g,
- "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");
- }
- export function strNumSize(tempNum) {
- var stringNum = tempNum.toString()
- var index = stringNum.indexOf(".")
- var newNum = stringNum;
- if (index != -1) {
- newNum = stringNum.substring(0, index)
- }
- return newNum.length
- }
|