How can I format a nullable DateTime with ToString()?

前端 未结 20 2378
面向向阳花
面向向阳花 2020-11-27 12:04

How can I convert the nullable DateTime dt2 to a formatted string?

DateTime dt = DateTime.Now;
Console.WriteLine(dt.ToString(\"yyyy-MM-dd hh         


        
20条回答
  •  执笔经年
    2020-11-27 12:45

    Maybe it is a late answer but may help anyone else.

    Simple is:

    nullabledatevariable.Value.Date.ToString("d")
    

    or just use any format rather than "d".

    Best

提交回复
热议问题