更新时间:2023-02-26 15:11:08
使用 TryParseExact
解析到日期时间
,那么的ToString
与格式字符串转换回...
Use TryParseExact
to parse to a DateTime
, then ToString
with a format string to convert back...
DateTime dt;
if (DateTime.TryParseExact(value, "MM/dd/yyyy hh:mm:ss tt",
CultureInfo.InvariantCulture, DateTimeStyles.None,
out dt))
{
string text = dt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
// Use text
}
else
{
// Handle failure
}