编程语言
首页 > 编程语言> > C# 字符串转日期格式

C# 字符串转日期格式

作者:互联网

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

 

标签:02,23,C#,createDate,resultCreateDate,DateTime,2022,字符串,格式
来源: https://www.cnblogs.com/YYkun/p/16316975.html