论坛里又有人问起日期怎样格式化为:2004-08-09 05:02:20这样的格式:于是写了一个左(右)对齐的函数.这函数等价于.NET里String对象的PadLeft和PadRight函数
Function PadLeft(Value,Length,sChar)
Dim strText,I
strText = String(Length,sChar)
strText = strText & Value
LeftPad = Right(strText,Length)
End Function
改一下最下面则为这样:
Function PadRight(Value,Length,sChar)
Dim strText,I
strText = String(Length,sChar)
strText = Value & strText
LeftPad = Left(strText,Length)
End Function
使用例子:日期显示
AA = year(now) & "-" & PadLeft(month(now),2,"0") & "-" & PadLeft(Day(now),2,"0") & " " & PadLeft(Hour(now),2,"0") & ":" & PadLeft(Minute(now),2,"0") & ":" & PadLeft(Second(now),2,"0")