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

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

posted on 2007-11-19 16:41  封起De日子  阅读(238)  评论(0编辑  收藏  举报

导航