.Net 中将字String 转换成 Date 型...

来源:互联网 发布:淘宝买苹果手机哪家好 编辑:程序博客网 时间:2024/03/28 18:21

e.g :  字符串:   20070221

在.net 中我们有时不能能使用  cdate 进行转换,会出错, 如 20070221   (无日期分隔符)

1 . 有时又可以使用 cdate 或 System.Convert.ToDateTime 待转换子函数,如果  "2007/03/21"

       Dim _date As String = "2007/03/21"

        MessageBox.Show(System.Convert.ToDateTime(_date).tostring("ddMMyyyy")

===

Result:    21032007

2 . 对于没有没有分隔符的的日期可以按下解的方法处理:

        Dim atwrt As String = "20070321.000000000"
        Dim s As String = Trim(atwrt.Split(",")(0))
        ' ----20070321----
        Dim idate As New DateTime(CInt(s.Substring(0, 4)), s.Substring(4, 2), s.Substring(6, 2))
        TextBox2.Text = idate.ToString("ddMMyyyy") 

===

Result:  21032007

原创粉丝点击