2014-02-05 156 views
0

您好我有數據庫日期被存儲在以下格式:2014年4月2日00:00:00如何把字符串格式的查詢字符串

現在我需要通過消除零檢索此日期使用以下格式的字符串格式: 04/02/2014

下面是我使用的檢索日期我的asp.net mvc的代碼:

if (scheduleresults.schedule_StartDate != null && scheduleresults.schedule_starttime != null) 
        { 
         sbs.Append("<td>" + scheduleresults.schedule_StartDate + scheduleresults.schedule_starttime + "</td>"); 
        } 

在上面的代碼中,開始日期中包含日期。

我如何把上述代碼的字符串格式?

回答

0

現在我需要使用字符串格式 是在下面的格式消除零檢索此日期: 2014年4月2日。

這應該工作 -

string date = "04/02/2014 00:00:00"; 
DateTime dt = DateTime.ParseExact(date, "dd/MM/yyyy hh:mm:ss", CultureInfo.InvariantCulture); 
Console.WriteLine(dt.ToString("dd/MM/yyyy")); 

將顯示 - 2014年4月2日

我如何將字符串格式上面的代碼?

你應該喜歡這個代碼的東西 -

scheduleresults.schedule_StartDate.ToString("dd/MM/yyyy");