Module:AgeCalculator
跳到导航
跳到搜索
- -- 由ChatGPT生成
- local p = {}
- -- 定义函数,用于计算年龄
- function p.calculateAge(frame)
- local args = frame:getParent().args
- local year = tonumber(args['year'])
- local month = tonumber(args['month'])
- local day = tonumber(args['day'])
- local currentYear = os.date('%Y')
- local currentMonth = os.date('%m')
- local currentDay = os.date('%d')
- -- 计算年龄
- local age = currentYear - year
- if currentMonth < month or (currentMonth == month and currentDay < day) then
- age = age - 1
- end
- -- 返回年龄
- return '该日期作为生日对应的年龄是:' .. age
- end
- return p