2010-07-22 129 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"));