Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 转换日期格式_C#_Winforms - Fatal编程技术网

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");