如何检查任何文本框的日期时间格式 [英] how to check the date time format of any text box
本文介绍了如何检查任何文本框的日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框,我想在其中输入"dd/MMM/YYYY"格式的日期.为此,我想检查那里的离开事件的文本框格式.所以告诉我C#编码检查文本框离开事件中的这种情况.
i have a textbox in which i want to give date in a "dd/MMM/YYYY" format. for this i want to check the textbox format in there leave event. so tell me the C# coding to check this condition in textbox leave event.
推荐答案
你好:
检查可以:
Hello :
to check you can :
if (DateTime.TryParseExact(TextBox1.Text, "MM/dd/yyyy", null, DateTimeStyles.None, out Test) == true)
否则,您无需检查即可直接将字符串更改为所需的任何格式:
else instead of checking you can directly change the string to any format you want :
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);
String.Format("{0:y yy yyy yyyy}", dt); // "8 08 008 2008" year
String.Format("{0:M MM MMM MMMM}", dt); // "3 03 Mar March" month
String.Format("{0:d dd ddd dddd}", dt); // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}", dt); // "4 04 16 16" hour 12/24
String.Format("{0:m mm}", dt); // "5 05" minute
String.Format("{0:s ss}", dt); // "7 07" second
String.Format("{0:f ff fff ffff}", dt); // "1 12 123 1230" sec.fraction
String.Format("{0:F FF FFF FFFF}", dt); // "1 12 123 123" without zeroes
String.Format("{0:t tt}", dt); // "P PM" A.M. or P.M.
String.Format("{0:z zz zzz}", dt); // "-6 -06 -06:00" time zone
问候...
regards...
尝试:
DateTime result;
if (DateTime.TryParseExact(myTextBox.Text, "dd/MMM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
{
// OK
}
else
{
// Error!
}
这篇关于如何检查任何文本框的日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文