Q
转换日期格式
2
A
回答
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"));
相关问题
- 1. 转换日期到MySQL日期格式
- 2. 转换日期格式/加密日期
- 3. 转换日期格式SQL
- 4. 转换日期格式
- 5. 转换日期格式
- 6. Metl - 转换日期格式
- 7. XSLT转换日期格式
- 8. 转换日期格式
- 9. 日期格式转换javascript
- 10. R:日期格式转换
- 11. 日期格式转换Ruby
- 12. 转换日期格式
- 13. CMake转换日期格式
- 14. 日期格式转换javascript
- 15. 转换日期格式
- 16. 转换日期格式
- 17. Java日期格式转换
- 18. javascript日期格式转换
- 19. javascript日期格式转换
- 20. 转换日期格式
- 21. 转换日期格式
- 22. iOS日期格式转换?
- 23. 转换日期格式Perl
- 24. 转换此日期格式
- 25. 转换日期格式
- 26. 转换日期格式
- 27. 转换日期格式
- 28. PHP日期格式转换
- 29. 转换为日期格式
- 30. Sql转换日期格式
可能重复的[如何任何类型的日期转换为DD /月/年](http://stackoverflow.com/questions/3248561/how-to-convert-any-type- date-to-dd-mm-yyyy) – 2010-07-22 14:25:48