string createDate="02 23 2022 5:19PM"; DateTime resultCreateDate; //判断字符串是否是日期格式 if (DateTime.TryParse(createDate.ToString(), out resultCreateDate)) { //是,输出resultCreateDate 输出:2022/02/23 05:19 } else {
//否 }
string createDate="02 23 2022 5:19PM"; System.Globalization.DateTimeFormatInfo a= new System.Globalization.CultureInfo("en-US", false).DateTimeFormat; a.ShortTimePattern = "t"; DateTime resultCreateDate= DateTime.Parse(createDate", a); //输出:2022/02/23 05:19