12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- const formatTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
- }
- const formatDateNotSecond = isoString => {
- if (isoString == undefined) return '';
- const date = new Date(isoString);
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are zero-based
- const day = String(date.getDate()).padStart(2, '0');
- const hours = String(date.getHours()).padStart(2, '0');
- const minutes = String(date.getMinutes()).padStart(2, '0');
- return `${year}-${month}-${day} ${hours}:${minutes}`;
- }
- const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : `0${n}`
- }
- const formatPhone = phone => {
- // 检查手机号是否有效
- if (!phone || phone.length !== 11) {
- return phone;
- }
- // 获取手机号前3位和后4位
- const start = phone.substring(0, 3);
- const end = phone.substring(7);
- // 将中间4位数字替换为星号
- const hidden = '****';
- // 返回处理后的手机号
- return start + hidden + end;
- }
- module.exports = {
- formatTime,
- formatDateNotSecond,
- formatPhone
- }
|