且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CONVERT MM / DD / YYYY HH:MI:在C#SS AM / PM为DD / MM / YYYY

更新时间: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
}