Format DateTime in C#

前端 未结 4 1480
执笔经年
执笔经年 2021-01-20 04:37

how can I format date to display in the following format 03-Feb-2011

I tried this statement but it did not work properly

string.Format(visitDate.Valu         


        
4条回答
  •  灰色年华
    2021-01-20 04:56

    string.format is valid but the parameter order you use are invalid:

    DateTime? visitDate = null;
    System.Diagnostics.Debug.WriteLine(visitDate == null ? "" : String.Format("{0:dd-MMM-yyyy}", visitDate));
    
    visitDate = DateTime.Now;
    System.Diagnostics.Debug.WriteLine(visitDate == null ? "" : String.Format("{0:dd-MMM-yyyy}", visitDate));
    

    That should do the trick.

提交回复
热议问题