转换日期格式

时间:2010-07-22 13:59:19

标签: c# winforms

如何转换:7/30/2010 11:05:53 AM

至:30/07/2010

3 个答案:

答案 0 :(得分:4)

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

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

- 使用Try Parse ---

// 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 :(得分:0)

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

答案 2 :(得分:0)

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