公司小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6 KiB

///格式化显示时间
let formatTime = function(time,format = 'YY.MM.DD hh:mm'){
let date = new Date(time * 1000);
let year = date.getFullYear();
let mouth = date.getMonth() + 1;
let day = date.getDay();
let hour = date.getHours();
let min = date.getMinutes();
//sec = date.getSeconds(),
let preArr = Array.apply(null,Array(10)).map(function(elem,index){
return '0' + index;
});
let newTime = format.replace(/YY/g,year).replace(/MM/g,preArr[mouth] || mouth)
.replace(/DD/g,preArr[day] || day)
.replace(/hh/g,preArr[hour] || hour)
.replace(/mm/g,preArr[min] || min);
return newTime;
}
3 years ago
/**
* @param {Object} number 需要格式化的数字
* @param {Object} decimals 保留几位小鼠
* @param {Object} dec_point 小数点符号
* @param {Object} thousands_sep 千分位符号
*/
let formatMoney = function(number,decimals,dec_point,thousands_sep){
number = (number + '').replace(/[^0-9+-Ee.]/g, '');
var n = !isFinite(+number) ? 0 : +number,
prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
s = '',
toFixedFix = function (n, prec) {
var k = Math.pow(10, prec);
return '' + Math.floor(n * k) / k;
};
s = (prec ? toFixedFix(n, prec) : '' + Math.floor(n)).split('.');
var re = /(-?\d+)(\d{3})/;
console.log(s)
while (re.test(s[0])) {
s[0] = s[0].replace(re, "$1" + sep + "$2");
}
if ((s[1] || '').length < prec) {
s[1] = s[1] || '';
s[1] += new Array(prec - s[1].length + 1).join('0');
}
return s.join(dec);
}
export default{
formatTime,
3 years ago
formatMoney,
}