C# 转换日期格式
如何转换:C# 转换日期格式,c#,winforms,C#,Winforms,如何转换:2010年7月30日上午11:05:53 收件人:30/07/2010 DateTime temp = DateTime.Parse("7/30/2010 11:05:53 AM"); string converted = temp.ToString("dd/MM/yyyy"); --使用Try-Parse--- 我相信你可以使用DateTime.Parse(“7/30/2010 11:05:53 AM”).ToShortDate()(取决于文化)这里没有人使用TryParse吗?
2010年7月30日上午11:05:53
收件人:30/07/2010
DateTime temp = DateTime.Parse("7/30/2010 11:05:53 AM");
string converted = temp.ToString("dd/MM/yyyy");
--使用Try-Parse---
我相信你可以使用
DateTime.Parse(“7/30/2010 11:05:53 AM”).ToShortDate()
(取决于文化)这里没有人使用TryParse吗?@fletcher询问,你会收到。可能的副本
// 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";
}
DateTime.ToString("dd/MM/yyyy");