程序开发时将系统日期转换成“2018-04-01”的格式
2018-05-26 本文已影响21人
听风别苑

在程序开发的时候,我们经常会用到将系统日期转换成“0000-00-00”格式的日期,对于频繁使用的代码,可以封装成一个自定义函数来调用,小编简单整理了一下,以备不时之需,也希望能够帮助需要帮助的人。内容如下:
Function NowDate() ' 将当前日期转换成“2018-04-01”的格式,在其他地方引用时,直接使用:NowDate()即可
nowyear = year(date())
nowmonth = month(date())
nowday = day(date())
if len(nowmonth)<2 then
nowmonth="0"&nowmonth
end if
if len(nowday)<2 then
nowday="0"&nowday
end if
nowdate = nowyear&"-"&nowmonth&"-"&nowday
End Function
Function TypeDate(str) ' 将指定日期转换成“2018-04-01”的格式,在其他地方引用时,直接使用:TypeDate(str)即可
nowyear = year(str)
nowmonth = month(str)
nowday = day(str)
if len(nowmonth)<2 then
nowmonth="0"&nowmonth
end if
if len(nowday)<2 then
nowday="0"&nowday
end if
TypeDate = nowyear&"-"&nowmonth&"-"&nowday
End Function