CRM-提交日期格式化
This commit is contained in:
@@ -22,19 +22,19 @@ export function maskIdNumber() {
|
|||||||
* 金额格式化
|
* 金额格式化
|
||||||
* num 金额
|
* num 金额
|
||||||
* decimals 保留几位小数,默认2位
|
* decimals 保留几位小数,默认2位
|
||||||
* units 默认 units ¥
|
* units 默认 units ¥
|
||||||
*/
|
*/
|
||||||
export function formatMoney(num, decimals,units){
|
export function formatMoney(num, decimals,units){
|
||||||
units = units || '¥ '
|
units = units || '¥ '
|
||||||
|
|
||||||
num = parseFloat(num/100);
|
num = parseFloat(num/100);
|
||||||
if (isNaN(num)) return units+0;
|
if (isNaN(num)) return units+0;
|
||||||
|
|
||||||
decimals = typeof decimals === 'undefined' ? 2 : decimals;
|
decimals = typeof decimals === 'undefined' ? 2 : decimals;
|
||||||
|
|
||||||
var parts = num.toFixed(decimals).split('.');
|
var parts = num.toFixed(decimals).split('.');
|
||||||
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||||
|
|
||||||
let retVal = 0;
|
let retVal = 0;
|
||||||
// let part1 = parts[1]
|
// let part1 = parts[1]
|
||||||
// if(parseInt(part1)==0){
|
// if(parseInt(part1)==0){
|
||||||
@@ -44,4 +44,24 @@ export function formatMoney(num, decimals,units){
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
return units+retVal;
|
return units+retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function dateFormat(fmt, date) {
|
||||||
|
let ret;
|
||||||
|
const opt = {
|
||||||
|
"Y+": date.getFullYear().toString(), // 年
|
||||||
|
"m+": (date.getMonth() + 1).toString(), // 月
|
||||||
|
"d+": date.getDate().toString(), // 日
|
||||||
|
"H+": date.getHours().toString(), // 时
|
||||||
|
"M+": date.getMinutes().toString(), // 分
|
||||||
|
"S+": date.getSeconds().toString() // 秒
|
||||||
|
// 有其他格式化字符需求可以继续添加,必须转化成字符串
|
||||||
|
};
|
||||||
|
for (let k in opt) {
|
||||||
|
ret = new RegExp("(" + k + ")").exec(fmt);
|
||||||
|
if (ret) {
|
||||||
|
fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return fmt;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user