如何从txtbox获取日期时间(文本模式日历) [英] how to get date time from txtbox (text mode calender)

查看:120
本文介绍了如何从txtbox获取日期时间(文本模式日历)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用文本框作为日历(文本框文本模式是日历)。

i想要将该文本框日期时间保存到我的数据库表中(列日期时间的数据类型)但是这个不工作的事情





 objClass.StartDateTime = Convert.ToDateTime(txtcalender.Text); 





这里显示错误

无法将字符串转换为日期

如果我省略convert.todatetime然后它显示我不能隐含地将字符串转换为日期。

如何操作如何从txtbox访问日期时间。

解决方案

使用此代码



 DateTime dateValue; 
CultureInfo culture = CultureInfo.CurrentCulture;
DateTimeStyles styles = DateTimeStyles.None;
DateTime.TryParse(datetimestring,culture,styles,out dateValue);


试试这个链接

Easy String to DateTime,DateTime to String and Formatting

i am using text box as calender (and that text box text mode is calender ).
i want to save that text box date time into my db table (data type of column datetime) but this thing not working


objClass.StartDateTime= Convert.ToDateTime(txtcalender.Text);



here it is showing me error
cannot convert string to date
if i ommit convert.todatetime then then it is show me cannot implicitly convert string to date.
what to do how can i access datetime from txtbox.

解决方案

Use this code

DateTime dateValue;
CultureInfo culture = CultureInfo.CurrentCulture;
DateTimeStyles styles = DateTimeStyles.None;
DateTime.TryParse(datetimestring,culture, styles, out dateValue);


Try this link
Easy String to DateTime, DateTime to String and Formatting


这篇关于如何从txtbox获取日期时间(文本模式日历)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆