Convert a two digit year to a four digit year

前端 未结 17 887
误落风尘
误落风尘 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

    Out of curiosity, from where do you get this data? From a form? In that case; I would simply ask the user to fill in (or somehow select) the year with four digits or get the users age and month/day of birth, and use that data to figure out what year they were born. That way, you wouldn't have to worry about this problem at all :)

    Edit: Use DateTime for working with this kind of data.

提交回复
热议问题