比如现在是2010年8月10日18点10分15秒
   我定义了一个字符串:  20100810181015  
  怎么样转成标准的时间格式:2010-08-10 18:10:15
 
 

解决方案 »

  1.   


    Private Sub Command1_Click()
        Dim strTime As String
        strTime = "20100808165530"
        Text1.Text = Mid(strTime, 1, 4) & "-" & _
                     Mid(strTime, 5, 2) & "-" & _
                     Mid(strTime, 7, 2) & " " & _
                     Mid(strTime, 9, 2) & ":" & _
                     Mid(strTime, 11, 2) & ":" & _
                     Mid(strTime, 13, 2)
    End Sub
      

  2.   

    Private Sub Command1_Click()
        Dim strDate As Date
        Dim strSj As String
        strSj = "20100810181015"
        strSj = Mid(strSj, 1, 4) & "-" & Mid(strSj, 5, 2) & "-" & Mid(strSj, 7, 2) & " " & Mid(strSj, 9, 2) & ":" & Mid(strSj, 11, 2) & ":" & Mid(strSj, 13, 2)
        strDate = CDate(strSj)
        Text1 = strDate
    End Sub
      

  3.   


    Private Sub Command1_Click()
        Dim t As String
        t = Format("20100810181015", "0000-00-00 00:00:00")
        MsgBox t
    End Sub
      

  4.   

    用三楼的方法就可以转成了,如果要转成日期格式加个CDATE()就可以了
    CDATE(Format("20100810181015", "0000-00-00 00:00:00"))
      

  5.   

    学猴哥的,我也用过format()好方便的。
      

  6.   

    Private Sub Command1_Click()
        Dim t As String
        t = Format("20100810181015", "yyyy-MM-dd hh:mm:ss")
        MsgBox t
    End Sub