Convert a two digit year to a four digit year

前端 未结 17 986
误落风尘
误落风尘 2020-12-25 12:13

This is a question of best practices. I have a utility that takes in a two digit year as a string and I need to convert it to a four digit year as a string. right now I do <

17条回答
  •  一个人的身影
    2020-12-25 12:46

    My two cents,

    Given an age range=[18, 100+], two digits year=90, I can do

    current year - twoDigitsYear = 2018 - 90 = 1928, I got 19, 28

    hence 19 is the first two digits of year of born, and 28 is the age, which is
    year=1990, age=28

    But it won't work when age 0 and 100 both included in the range, same to some of the other answers here.

提交回复
热议问题