需求:
需要实现 1岁2月3天
这样的格式
方法:
export const getBirthSlot = (date) => {
let birthDay = new Date(date)
let nowDate = new Date()
let date1 = Date.parse(birthDay)
let date2 = Date.parse(nowDate)
let day = Math.ceil((date2 - date1) / (60 * 60 * 1000 * 24))
let age = ''
let year = Math.floor(day / 365)
let y = day % 365
let month = Math.floor(y / 30)
let d = Math.floor(day % 365 % 30)
age += year + '岁' + month + '月' + d + '天'
return age
}
网友评论