日期格式化
点击查看代码
let dateFormatter = function (value) {
const options = {
year: 'numeric',
month: '2-digit',
day: '2-digit',
timeZone: 'Asia/Tokyo'
};
// return new Date(value).toLocaleDateString("ja-JP", options);
return new Intl.DateTimeFormat('ja-JP',options).format(new Date(value));
};
let dateTimeFormatter = function (value) {
const options = {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
timeZone: 'Asia/Tokyo'
};
return new Date(value).toLocaleString("ja-JP", options);
};
货币格式化
点击查看代码
let moneyFormatter = function (value) {
if (typeof value === 'number' && !isNaN(value)) {
return new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(value);
// return value.toLocaleString('ja-JP', {style: 'currency', currency: 'JPY'});
}
return '';
};
参考地址:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
浙公网安备 33010602011771号