2011-04-07 105 views
4

我嘗試將字符串轉換爲「hh:mm:ss」或「dd.mm.yyyy hh :MM:SS」,但我沒有做到:( 代碼那樣:字符串日期時間「hh:mm:ss」或「dd.mm.yyyy hh:mm:ss」格式

public DateTime[] tarihSaat = new DateTime[documentRowCount] 

string c = "27.12.2010 00:00:00" 

tarihSaat[0] = DateTime.ParseExact(c, "dd.MM.yyyy hh:mm:ss", CultureInfo.InvariantCulture); 

但它沒有work..Any建議

+0

您的代碼示例工作得很好,我 - 你確定'documentRowCount'> 0? – BrokenGlass 2011-04-07 16:26:58

+0

究竟是如何不起作用?你有錯誤的價值嗎?它崩潰了嗎? – eldarerathis 2011-04-07 16:27:46

+0

你能告訴我們程序*在做什麼嗎?它拋出異常嗎?它是否產生了錯誤的日期? – 2011-04-07 16:28:55

回答

8

你正在做正確的方式的一切,但也許你不必hh,但HH這樣的:

tarihSaat[0] = DateTime.ParseExact(c, "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture); 

hh是12小時制,看起來好像你是24小時格式解析,讓你需要HH

0
using System; 
using System.Globalization; 

DateTime.Parse("27.12.2010 00:00:00", 
       new CultureInfo("en-GB")).ToLongDateString(); 

//給你 「週一,2010年12月27」

相關問題