可否分别获取: Option Explicit Dim dDate As String Private Sub Command1_Click() dDate = Year(Now) & "年" & Month(Now) & "月" & Day(Now) & "日" Debug.Print dDate '结果是2009年4月27日 End Sub
'自己写一个格式化日期函数 Dim MyDate As String, MyFormatDate As String, strY As String, strM As String, strD As String MyDate = Now strY = Year(MyDate) strM = Month(MyDate) strD = Day(MyDate) '若要显示两位格式的月和天,加入以下两行语句 If Len(strM) < 2 Then strM = "0" & strM If Len(strD) < 2 Then strD = "0" & strD
可否分别获取:
Option Explicit
Dim dDate As String
Private Sub Command1_Click()
dDate = Year(Now) & "年" & Month(Now) & "月" & Day(Now) & "日"
Debug.Print dDate '结果是2009年4月27日
End Sub
Dim MyDate As String, MyFormatDate As String, strY As String, strM As String, strD As String
MyDate = Now
strY = Year(MyDate)
strM = Month(MyDate)
strD = Day(MyDate)
'若要显示两位格式的月和天,加入以下两行语句
If Len(strM) < 2 Then strM = "0" & strM
If Len(strD) < 2 Then strD = "0" & strD
MyFormatDate = strY & "-" & strM & "-" & strD '年月日
'MyFormatDate = strD &"-"strM & "-" &strM '日月年 Debug.Print MyFormatDate
你用以下的函数试试,我在下面给你写上方法:
print FormatDateTime(Date,vbShortTime) 返回一个日期和时间的显示格式。常数 值 描述 vbGeneralDate 0 显示日期和/或时间。如果有日期部分,则用短日期格式显示。如果有时间部分,则用长时间格式显示。如果都有,两部分都显示。 print FormatDateTime(now,vbGeneralDate)2009-1-28 0:07:03----------------------------------------------------------------------------vbLongDate 1 用计算机区域设置值中指定的长日期格式显示日期。print FormatDateTime(now,vbLongDate)2009年1月28日 ----------------------------------------------------------------------------vbShortDate 2 用计算机区域设置值中指定的短日期格式显示日期。 print FormatDateTime(now,vbShortDate)2009-1-28----------------------------------------------------------------------------vbLongTime 3 用计算机区域设置值中指定的时间格式显示时间。print FormatDateTime(now,vbLongTime)0:08:56 ----------------------------------------------------------------------------vbShortTime 4 用24小时格式(hh:mm)显示时间。 print FormatDateTime(now,vbShortTime)00:09----------------------------------------------------------------------------