vbs教程《日期时间》

dim curdate,curtime,curdatetime
dim mydate,mytime,mydatetime

rem 获取当前日期: 年/月/日
curdate = date()

rem 获取当前时间: 时:分:秒
curtime = time()

rem 获取现在时间: 年/月/日 时:分:秒
curdatetime = now()

rem 将有效数据转成时间类型
mydate = cdate("2008/09/10")
mytime = cdate("18:19:20")
mydatetime = cdate("2009/10/11 19:20:21")

rem 获取年
rem msgbox(year(curdatetime))
rem msgbox(year(curdate))
rem msgbox(year(mydatetime))
rem msgbox(year(mydate))
rem msgbox(year("2017/11/12"))
rem msgbox(year("2017/11"))
rem msgbox(year("2018-10-20"))
rem msgbox(year("2018-10"))

rem 获取月(1~12)
rem msgbox(month(curdatetime))
rem msgbox(month(curdate))
rem msgbox(month(mydatetime))
rem msgbox(month(mydate))
rem msgbox(month("2017/11/12"))
rem msgbox(month("2017/11"))
rem msgbox(month("11/12"))
rem msgbox(month("2018-10-20"))
rem msgbox(month("2018-10"))
rem msgbox(month("10-20"))

rem 获取日(1~31)
rem msgbox(day(curdatetime))
rem msgbox(day(curdate))
rem msgbox(day(mydatetime))
rem msgbox(day(mydate))
rem msgbox(day("2017/11/12"))
rem msgbox(day("11/12"))
rem msgbox(day("2018-10-20"))
rem msgbox(day("10-20"))

rem 获取星期几(1~7) weekday(date,type[默认1从周日开始/2从周一开始])
rem msgbox(weekday(curdatetime))
rem msgbox(weekday(curdate))
rem msgbox(weekday(mydatetime))
rem msgbox(weekday(mydate))
rem msgbox(weekday("2016/12/30"))

rem 获取时(0~23)
rem msgbox(hour(curdatetime))
rem msgbox(hour(curtime))
rem msgbox(hour(mydatetime))
rem msgbox(hour(mytime))
rem msgbox(hour("12:02:30"))
rem msgbox(hour("12:02"))

rem 获取分(0~59)
rem msgbox(minute(curdatetime))
rem msgbox(minute(curtime))
rem msgbox(minute(mydatetime))
rem msgbox(minute(mytime))
rem msgbox(minute("12:02:30"))
rem msgbox(minute("12:02"))

rem 获取秒(0~59)
rem msgbox(second(curdatetime))
rem msgbox(second(curtime))
rem msgbox(second(mydatetime))
rem msgbox(second(mytime))
rem msgbox(second("12:02:30"))

  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值