论坛里又有人问起日期怎样格式化为: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")
万能时间补位代码
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一段自动补位的函数
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 计数
getbit 共几位
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年11月18日
2024年11月18日
- APM亚流新世代《一起冒险》[320K/MP3][68.66MB]
- FIM《天伦乐》(DaydreamsAndLullabies)24K金碟[WAV+CUE]
- 【雨果唱片】中国管弦乐《鹿回头》
- 【雨果唱片】中国管弦乐《鹿回头》WAV
- APM亚流新世代《一起冒险》[FLAC/分轨][106.77MB]
- 崔健《飞狗》律冻文化[WAV+CUE][1.1G]
- 罗志祥《舞状元 (Explicit)》[320K/MP3][66.77MB]
- 尤雅.1997-幽雅精粹2CD【南方】【WAV+CUE】
- 张惠妹.2007-STAR(引进版)【EMI百代】【WAV+CUE】
- 群星.2008-LOVE情歌集VOL.8【正东】【WAV+CUE】
- 罗志祥《舞状元 (Explicit)》[FLAC/分轨][360.76MB]
- Tank《我不伟大,至少我能改变我。》[320K/MP3][160.41MB]
- Tank《我不伟大,至少我能改变我。》[FLAC/分轨][236.89MB]
- CD圣经推荐-夏韶声《谙2》SACD-ISO
- 钟镇涛-《百分百钟镇涛》首批限量版SACD-ISO