+ -
当前位置:首页 → 问答吧 → 日期转换的问题

日期转换的问题

时间:2011-07-22

来源:互联网

请问如何将text中输入的日期转换成yyyy/m/dd的形式啊?
比如将 20110702 转换成 2011/7/2

作者: wiggerzhang   发布时间: 2011-07-22

format

作者: patrickkong   发布时间: 2011-07-22

1:修改区域语言选项中的日期分隔符“-” 为“/”
2:
VB code

Private Sub Command1_Click()
   MsgBox GetFormatDate(Now())
End Sub
Private Function GetFormatDate(ByVal tmDate As Date) As String
    GetFormatDate = Year(Date) & "/" & Month(tmDate) & "/" & Day(tmDate)
End Function

作者: BestBadGod   发布时间: 2011-07-22

用format会报出溢出

楼主自己写一个写的方法解决吧

作者: yunmingqu   发布时间: 2011-07-22

简单的字符串截取

作者: yunmingqu   发布时间: 2011-07-22

1:修改区域语言选项中的日期分隔符“-” 为“/”,然后用format(now(),"yyyy-m-dd")
2:
VB code

Private Sub Command1_Click()
   MsgBox GetFormatDate(Now())
End Sub
Private Function GetFormatDate(ByVal tmDate As Date) As String
    GetFormatDate = Year(tmDate) & "/" & Month(tmDate) & "/" & Day(tmDate)
End Function


作者: BestBadGod   发布时间: 2011-07-22

VB code
dim s as string
s="20110702"
debug.print format(s,"####/##/##") '2011/07/02
debug.print mid(s,1,4)+"/"+CStr(Val(mid(s,5,2)))+"/"+CStr(Val(mid(s,7,2))) '2011/7/2

作者: zhao4zhong1   发布时间: 2011-07-22

引用 6 楼 zhao4zhong1 的回复:
VB code
dim s as string
s="20110702"
debug.print format(s,"####/##/##") '2011/07/02
debug.print mid(s,1,4)+"/"+CStr(Val(mid(s,5,2)))+"/"+CStr(Val(mid(s,7,2))) '2011/7/2

抄袭一下
VB code
Dim s As String
s = "20110702"
Debug.Print Format(Format(s, "####/##/##"), "YYYY\/M\/D") '2011/7/2

作者: yachong   发布时间: 2011-07-22

上面那个"YYYY\/M\/D"是我瞎蒙的,不知道有没有副作用

作者: yachong   发布时间: 2011-07-22

dim st_date as string
st_date=text.text
st_date=Format(st_date,"####-##-##")
d_date =CDate(st_date)

作者: lilisaxxi   发布时间: 2011-07-22

热门下载

更多