tmp
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
// 根据出生年月(YYYY-MM-DD)计算年龄
|
||||
function calcAge(birth) {
|
||||
if (!birth) return 0
|
||||
const d = new Date(birth)
|
||||
if (isNaN(d.getTime())) return 0
|
||||
const now = new Date()
|
||||
let age = now.getFullYear() - d.getFullYear()
|
||||
const m = now.getMonth() - d.getMonth()
|
||||
if (m < 0 || (m === 0 && now.getDate() < d.getDate())) age--
|
||||
return age > 0 ? age : 0
|
||||
}
|
||||
|
||||
module.exports = { calcAge }
|
||||
Reference in New Issue
Block a user