Convert a two digit year to a four digit year

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

    The .NET framework has a method that does exactly what you want:

    int fourDigitYear = CultureInfo.CurrentCulture.Calendar.ToFourDigitYear(twoDigitYear)
    

    That way you will correctly adhere to current regional settings as defined in Control Panel (or group policy):

    Regional settings

提交回复
热议问题