VB获得时间

来源:百度知道 编辑:UC知道 时间:2024/05/25 00:22:43
比如我有2009-3-16 9:56:25,我能不能取出里面的年月日的信息,要用日期函数的,不要用MID这种自负函数

Private Sub Command1_Click()
Dim d As Date
d = "2009-3-16 9:56:25"
Print Year(d) '年
Print Month(d) '月
Print Day(d) '日
End Sub

date(2009-3-16 9:56:25) 是获取年
month(2009-3-16 9:56:25) 是获取月份
day(2009-3-16 9:56:25)是获取日
可以获取当前电脑的时间来测试
下面的代码是获取电脑当前时间
str1=now
可以这样测试
date(str1)或date(now)

MsgBox Format("2009-12-12 12:00:00", "yyyy-mm-dd")

date()就可以了