Last active
September 11, 2020 16:34
-
-
Save lumixraku/232ec98611f6b81cb47e669299294402 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 运用正则去掉空格 | |
' s123s'.replace(/^(\s*)(.+)(\s*)$/, '$2') | |
// 日期操作 | |
const dataPattern = (str, format = '-') => { | |
if (!str) { | |
return new Date() | |
} | |
const dateReg = new RegExp(`^(\\d{2})${format}(\\d{2})${format}(\\d{4})$`) | |
const [, month, day, year] = dateReg.exec(str) | |
return new Date(`${month}, ${day} ${year}`) | |
} | |
console.log(dataPattern('12-25-1995')) // Mon Dec 25 1995 00:00:00 GMT+0800 (中国标准时间) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment