转换成字符串在文本框中DD / MM / YYYY日期转换成、字符串、框中、文本

由网友(古城白衣少年殇彡)分享简介:我要如何转换成字符串在文本框中DD / MM / YYYY日期格式,我的意思是财产以后这样的:日期D =日期(textBox.Text);我想用它作为SQL参数为日期数据类型如下:command.Parameters.Add(新NpgsqlParameter(V5,NpgsqlDbType.Date));解决方案 您可...

我要如何转换成字符串在文本框中DD / MM / YYYY日期格式,我的意思是财产以后这样的:

 日期D =日期(textBox.Text);
 

我想用它作为SQL参数为日期数据类型如下:

  command.Parameters.Add(新NpgsqlParameter(V5,NpgsqlDbType.Date));
 

解决方案 怎样把常规格式yyyymmdd转换成文本格式yyyy mm dd我只会第一步 text 单元格, yyyy mm dd 再怎么做谢谢

您可以使用的 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 
}

阅读全文

相关推荐

最新文章