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配合使用控制日期的输入格式就可以了。
所以对时间的处理可以选择控制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配合使用控制日期的输入格式就可以了。
相关文章推荐
- How to convert any valid date string to a DateTime.
- How to convert from string to datetime in sql server? - Sealyu - BlogJava
- How to convert from int to string in objective c
- DateTime.ToString("dd/MM/yyyy");后,不能直接Convert.ToDateTime的解决:
- Convert Datetime to String in Sql Server
- How to convert a byte to its binary string representation
- 如何将String类型的数组转换成ArrayList(How to convert a string array to arraylist)
- In Java, how do I read/convert an InputStream to a String? - Stack Overflow
- How to convert string to Guid type.
- How to convert string to wstring?
- 【Z一贴】C++ String: How to convert a string into a numeric type?
- How to properly convert SecureString to String
- Oracle Convert DateTime to String
- How to convert char array to String in Java
- C# How to Convert String to ASCII OR how to convert ASCII To String
- Convert Datetime to String in Sql Server
- How can I convert String to Int in C#?
- Convert string to DateTime
- Convert Datetime to String in Sql Server (转)
- How to convert a String to Stream