代码如下:
显示结果:
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