1. 程式人生 > >vbs教程《日期時間》

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"))