美文网首页程序员
程序开发时将系统日期转换成“2018-04-01”的格式

程序开发时将系统日期转换成“2018-04-01”的格式

作者: 听风别苑 | 来源:发表于2018-05-26 11:11 被阅读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

相关文章

网友评论

    本文标题:程序开发时将系统日期转换成“2018-04-01”的格式

    本文链接:https://www.haomeiwen.com/subject/xpfmjftx.html