Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

替换被弃用的RegExp.$1、substr #1937

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions web/src/utils/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,32 @@
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) {
// eslint-disable-next-line no-extend-native
Date.prototype.Format = function(fmt) {
const o = {
'M+': this.getMonth() + 1, // 月份
'd+': this.getDate(), // 日
'h+': this.getHours(), // 小时
'm+': this.getMinutes(), // 分
's+': this.getSeconds(), // 秒
'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
S: this.getMilliseconds() // 毫秒
'S': this.getMilliseconds() // 毫秒
}
if (/(y+)/.test(fmt)) {
const reg = /(y+)/
if (reg.test(fmt)) {
const t = reg.exec(fmt)[1]
fmt = fmt.replace(
RegExp.$1,
(this.getFullYear() + '').substr(4 - RegExp.$1.length)
t,
(this.getFullYear() + '').substring(4 - t.length)
)
}
for (const k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
for (let k in o) {
const regx = new RegExp('(' + k + ')')
if (regx.test(fmt)) {
const t = regx.exec(fmt)[1]
fmt = fmt.replace(
RegExp.$1,
RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
t,
t.length === 1 ? o[k] : ('00' + o[k]).substring(('' + o[k]).length)
)
}
}
Expand Down
Loading