转换成字符串在文本框中DD / MM / YYYY日期 [英] convert string in a text box to dd/mm/yyyy date
本文介绍了转换成字符串在文本框中DD / MM / YYYY日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要如何转换成字符串在文本框中DD / MM / YYYY日期格式,我的意思是财产以后这样的:
日期D =日期(textBox.Text);
我想用它作为SQL参数为日期
数据类型如下:
command.Parameters.Add(新NpgsqlParameter(V5,NpgsqlDbType.Date));
解决方案
您可以使用的 TryParseExact()
方式:
//使用System.Globalization;
日期时间指明MyDate;
如果(DateTime.TryParseExact(textBox.Text,DD / MM / YYYY,CultureInfo.InvariantCulture,DateTimeStyle.None,出指明MyDate)){
//做一点事
}
How do I convert a string in a text box to dd/mm/yyyy date form, I mean somthing like:
Date d = Date(textBox.Text);
I would like to use it as a parameter in SQL as Date
data-type as following:
command.Parameters.Add( new NpgsqlParameter("v5", NpgsqlDbType.Date));
解决方案
You could use the TryParseExact()
method:
//using System.Globalization;
DateTime myDate;
if(DateTime.TryParseExact(textBox.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyle.None, out myDate)){
//do something
}
这篇关于转换成字符串在文本框中DD / MM / YYYY日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文