111,125
社区成员
发帖
与我相关
我的任务
分享private DateTime StrToDateTime(string src, string format)
{
DateTime dt;
if (DateTime.TryParseExact(src, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
return dt;
else
return DateTime.MinValue;
}
//调用
DateTime test = StrToDateTime(textBox1.Text, textBox2.Text);
if(test != DateTime.MinValue)
MessageBox.Show(test.ToString("yyyy-MM-dd HH:mm:ss"));string s = "20070419090909";
DateTime vDateTime;
if (DateTime.TryParseExact(s, "yyyyMMddHHmmss", null,
System.Globalization.DateTimeStyles.None, out vDateTime))
MessageBox.Show(vDateTime.ToString());
else MessageBox.Show("输入错误");
string tiString = "1977-02-10";
DateTime dt1 = DateTime.Parse(tiString);
//MessageBox.Show(dt1.Day.ToString()+"-"+dt1.Year.ToString()+"-"+dt1.Month.ToString());