2010-07-22 124 views
2

如何轉換:7/30/2010 11:05:53 AM轉換日期格式

到:30/07/2010

+0

可能重複的[如何任何類型​​的日期轉換爲DD /月/年](http://stackoverflow.com/questions/3248561/how-to-convert-any-type- date-to-dd-mm-yyyy) – 2010-07-22 14:25:48

回答

4
DateTime temp = DateTime.Parse("7/30/2010 11:05:53 AM"); 

string converted = temp.ToString("dd/MM/yyyy"); 

- 使用嘗試解析---

// Try Parse is better because if the format is invalid an exception is not thrown. 
DateTime temp; 

string converted = string.Empty; 

if (DateTime.TryParse("7/30/2010 11:05:53 AM", out temp)) 
{ 
    // True means Date was converted properly 
    converted = temp.ToString("dd/MM/yyyy"); 
} 
else 
{ 
    converted = "ERROR in PARSING"; 
} 
+1

.NET有時很漂亮 – 2010-07-22 14:02:53

+0

這裏沒有人使用TryParse? – fletcher 2010-07-22 14:10:08

+0

@fletcher問,你會收到。 – 2010-07-22 14:12:35

0
DateTime.ToString("dd/MM/yyyy"); 
0

我相信你可以使用DateTime.Parse("7/30/2010 11:05:53 AM").ToShortDate()(取決於文化)

0

嘗試的

DateTime dtTest = Convert.ToDateTime("7/30/2010 11:05:53 AM"); 
Response.Write(dtTest.ToString("dd/MM/yyyy"));