What's the simplest way to format a .NET DateTime according to YYYYMMDD or the like?

后端 未结 5 944
春和景丽
春和景丽 2020-12-11 09:20

I have a DateTime class and wish to display it according to some format... in this case, I specifically want to format it as YYYYMMDD format.

What\'s the best C#/.NE

5条回答
  •  囚心锁ツ
    2020-12-11 10:12

    myDateTime.ToString("yyyyMMdd")
    

    Here you can find a comprehesive list of DateTime patterns and pattern characters: DateTime.ToString() Patterns

提交回复
热议问题