• 博客园Logo
  • 首页
  • 新闻
  • 博问
  • 会员
  • 闪存
  • 班级
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 简洁模式 ... 退出登录
    注册 登录
激情 希望 斗志昂扬
Records of growth process 专注微软技术
博客园    首页    新随笔    联系   管理    订阅  订阅

ASP 时间格式化函数

代码
ASP 时间格式化函数 好处是你经常按日期排列文章的时候~ 9月3号会比9月21号靠前,很不爽,你格式化日期09月03号(1位数补0)就不会出现这个事情了
 
Public Function FormatDate(DateAndTime, para)
On Error Resume Next
Dim y, m, d, h, mi, s, strDateTime
FormatDate 
= DateAndTime
If Not IsNumeric(para) Then Exit Function
If 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
mi 
= CStr(Minute(DateAndTime))
If Len(mi) 
= 1 Then mi = "0" & mi
s 
= CStr(Second(DateAndTime))
If Len(s) 
= 1 Then s = "0" & s
Select Case para
Case 
"1":strDateTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
Case 
"2":strDateTime = y & "-" & m & "-" & d
Case 
"3":strDateTime = y & "/" & m & "/" & d
Case 
"4":strDateTime = y & "年" & m & "月" & d & "日"
Case 
"5":strDateTime = m & "-" & d
Case 
"6":strDateTime = m & "/" & d
Case 
"7":strDateTime = m & "月" & d & "日"
Case 
"8":strDateTime = y & "年" & m & "月"
Case 
"9":strDateTime = y & "-" & m
Case 
"10":strDateTime = y & "/" & m
Case Else
strDateTime 
= DateAndTime
End Select
FormatDate 
= strDateTime
End Function

调用方法:
<%=FormatDate(now(),2)%>

 
posted @ 2009-11-27 15:04  贤  阅读(298)  评论(0)  编辑  收藏  举报
弹尽粮绝,会员救园:会员上线,命悬一线
刷新页面返回顶部
Copyright © 2023 贤
Powered by .NET 7.0 on Kubernetes