您的位置:首页 > 其它

How to convert a String to DateTime

2006-12-13 11:17 435 查看
昨天在做项目的时候遇到了这个问题,因为在WebControl里面并不包含对DateTimePicker控件的定义,
所以对时间的处理可以选择控制String的格式,然后将String转化成DateTime再储存到数据库中。
如何将String转化成DateTime类型呢,如下面代码所示:

// Set the birthday of the employee.
if (!string.IsNullOrEmpty(txtBirthday.Text))
// Set the birthday of the employee.
if (!string.IsNullOrEmpty(txtBirthday.Text))
^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$

所以在界面txtBirthday输入框增加一个RegularExpressionValidator配合使用控制日期的输入格式就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: