12345678910111213141516171819202122232425262728293031323334353637 |
- /**
- * 处理unix时间戳,转换为可阅读时间格式
- * @param unix
- * @param format
- * @returns {*|string}
- */
- export function unixToDate(unix, format) {
- let _format = format || 'yyyy-MM-dd hh:mm:ss'
- const d = new Date(unix * 1000)
- const o = {
- 'M+': d.getMonth() + 1,
- 'd+': d.getDate(),
- 'h+': d.getHours(),
- 'm+': d.getMinutes(),
- 's+': d.getSeconds(),
- 'q+': Math.floor((d.getMonth() + 3) / 3),
- S: d.getMilliseconds()
- }
- if (/(y+)/.test(_format)) _format = _format.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length))
- for (const k in o) if (new RegExp('(' + k + ')').test(_format)) _format = _format.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
- return _format
- }
- /**
- * 13888888888 -> 138****8888
- * @param mobile
- * @returns {*}
- */
- export function secrecyMobile(mobile) {
- mobile = String(mobile)
- if (!/\d{11}/.test(mobile)) {
- return mobile
- }
- return mobile.replace(/(\d{3})(\d{4})(\d{4})/, '$1****$3')
- }
|