文章詳情頁
ASP中實現(xiàn)字符部位類似.NET里String對象的PadLeft和PadRight函數(shù)
瀏覽:444日期:2022-06-04 18:24:58
論壇里又有人問起日期怎樣格式化為:2004-08-09 05:02:20這樣的格式:于是寫了一個左(右)對齊的函數(shù).這函數(shù)等價于.NET里String對象的PadLeft和PadRight函數(shù)
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")
萬能時間補(bǔ)位代碼
Public Function ForMatDate(DateAndTime, Para) "格式化日期(日期時間,格式) Dim Y, M, D, H, F, S IF Not ISNumeric(Para) Or Not ISDate(DateAndTime) Then Exit Function Y = CStr(Year(DateAndTime)) M = CStr(Month(DateAndTime)):IF Len(M) = 1 Then M = "0" & M D = CStr(Day(DateAndTime)):IF Len(D) = 1 Then D = "0" & D H = CStr(Hour(DateAndTime)):IF Len(H) = 1 Then H = "0" & H F = CStr(Minute(DateAndTime)):IF Len(F) = 1 Then F = "0" & F S = CStr(Second(DateAndTime)):IF Len(S) = 1 Then S = "0" & S Select Case Para Case "0" ForMatDate = Y & "-" & M & "-" & D & " " & H & ":" & F & ":" & S Case "1" ForMatDate = Y & "-" & M & "-" & D & " " & H & ":" & F Case "2" ForMatDate = Y & "-" & M & "-" & D Case "3" ForMatDate = Y & "/" & M & "/" & D Case "4" ForMatDate = Y & "年" & M & "月" & D & "日" Case "5" ForMatDate = M & "-" & D & " " & H & ":" & F Case "6" ForMatDate = M & "/" & D Case "7" ForMatDate = M & "月" & D & "日" Case "8" ForMatDate = Y & "年" & M & "月" Case "9" ForMatDate = Y & "-" & M Case "10" ForMatDate = Y & "/" & M Case "11" ForMatDate = right(Y,2) & "-" &M & "-" & D & " " & H & ":" & F Case "12" ForMatDate = right(Y,2) & "-" &M & "-" & D Case "13" ForMatDate = M & "-" & D Case Else ForMatDate = DateAndTime End Select End Function Response.Write ForMatDate(Now,"2")
asp一段自動補(bǔ)位的函數(shù)
function formatsn(getnum,getbit) dim formatsnnum,formatsnpre,formatsnj formatsnnum = getbit – len(getnum) for formatsnj = 1 to formatsnnum formatsnpre = formatsnpre & "0" next formatsn = formatsnpre & getnum end function
使用方法
formatsn(getnum,getbit)
getnum 計數(shù)
getbit 共幾位
到此這篇關(guān)于ASP中實現(xiàn)字符部位類似.NET里String對象的PadLeft和PadRight函數(shù)的文章就介紹到這了,更多相關(guān)asp PadLeft和PadRight內(nèi)容請搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!
標(biāo)簽:
ASP
相關(guān)文章:
1. ASP.NET MVC通過勾選checkbox更改select的內(nèi)容2. ASP基礎(chǔ)知識Command對象講解3. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明4. 完美的ASP分頁腳本代碼5. 用Php模擬asp.net的頁面模型6. ASP中實現(xiàn)分頁顯示的七種方法7. asp中Request.ServerVariables的參數(shù)集合8. asp知識整理筆記1(問答模式)9. asp.net core項目授權(quán)流程詳解10. ASP.NET堆和棧二之值類型和引用類型的參數(shù)傳遞和內(nèi)存分配
排行榜
