在ASP(VB)中自定义日期格式的函数
Posted Snowdust
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在ASP(VB)中自定义日期格式的函数相关的知识,希望对你有一定的参考价值。
代码如下:
显示结果:
Function
AddZero(val, digit)
Dim Ret
Ret = CStr (val)
Ret = Replace ( Space (digit - Len (val)), " " , " 0 " ) & Ret
AddZero = ret
End Function
Function FormatDataTime(dt, format)
Dim ret
ret = Replace (format, " MM " , AddZero( Month (dt), 2 ))
ret = Replace (ret, " M " , Month (dt))
ret = Replace (ret, " mm " , AddZero( Minute (dt), 2 ))
ret = Replace (ret, " m " , Minute (dt))
ret = UCase (ret)
ret = Replace (ret, " YYYY " , Year (dt))
ret = Replace (ret, " DD " , Day (dt))
ret = Replace (ret, " D " , AddZero( Day (dt), 2 ))
ret = Replace (ret, " HH " , Hour (dt))
ret = Replace (ret, " H " , AddZero( Hour (dt), 2 ))
ret = Replace (ret, " SS " , AddZero( Second (dt), 2 ))
ret = Replace (ret, " S " , Second (dt))
FormatDataTime = ret
End Function
Response.Write FormatDataTime( Now , " yyyy-MM-dd hh:mm:ss " )
Dim Ret
Ret = CStr (val)
Ret = Replace ( Space (digit - Len (val)), " " , " 0 " ) & Ret
AddZero = ret
End Function
Function FormatDataTime(dt, format)
Dim ret
ret = Replace (format, " MM " , AddZero( Month (dt), 2 ))
ret = Replace (ret, " M " , Month (dt))
ret = Replace (ret, " mm " , AddZero( Minute (dt), 2 ))
ret = Replace (ret, " m " , Minute (dt))
ret = UCase (ret)
ret = Replace (ret, " YYYY " , Year (dt))
ret = Replace (ret, " DD " , Day (dt))
ret = Replace (ret, " D " , AddZero( Day (dt), 2 ))
ret = Replace (ret, " HH " , Hour (dt))
ret = Replace (ret, " H " , AddZero( Hour (dt), 2 ))
ret = Replace (ret, " SS " , AddZero( Second (dt), 2 ))
ret = Replace (ret, " S " , Second (dt))
FormatDataTime = ret
End Function
Response.Write FormatDataTime( Now , " yyyy-MM-dd hh:mm:ss " )
2006-12-31 11:37:27
以上是关于在ASP(VB)中自定义日期格式的函数的主要内容,如果未能解决你的问题,请参考以下文章
我可以在 asp.net(vb) 中自定义 ajax 文件上传吗?