Convert a two digit year to a four digit year

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

    To change a 2-digit year to 4-digit current or earlier -

    year = year + (DateTime.Today.Year - DateTime.Today.Year%100);
    if (year > DateTime.Today.Year)
                    year = year - 100;
    

提交回复
热议问题