asp 将日期格式化为需要的格式

所属分类: 网络编程 / ASP编程 阅读数: 534
收藏 0 赞 0 分享
<%
'******************************
'函数:FormatDate(DateAndTime, para)
'参数:DateAndTime,要格式化的日期时间;para,样式。
'作者:阿里西西
'日期:2007/7/12
'描述:将日期格式化为需要的格式
'示例:<%=FormatDate(now(), 3)%>
'******************************
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 & " " & h & ":" & mi
  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 "11"
   strDateTime = right(y,2) & "-" &m & "-" & d & " " & h & ":" & mi
  Case "12"
   strDateTime = right(y,2) & "-" &m & "-" & d
  Case "13"
   strDateTime = m & "-" & d
  Case Else
   strDateTime = DateAndTime
  End Select
 FormatDate = strDateTime
End Function
%>
更多精彩内容其他人还在看

IIS访问ASP页面时报错The requested resource is in use.的解决办法

IIS访问ASP页面时报错The requested resource is in use.的解决办法
收藏 0 赞 0 分享

错误类型:Provider (0x80004005)未指定的错误 的一个处理方法

一般情况下asp可以正常运行,但只要连接数据库就提示,Microsoft JET Database Engine 错误'80004005'
收藏 0 赞 0 分享

关于“未指定的错误”的问题 的比较正解的解决方法

关于“未指定的错误”的问题 的比较正解的解决方法
收藏 0 赞 0 分享

关于asp+access的安全问题分析

关于asp+access的安全问题分析
收藏 0 赞 0 分享

把RS.GetRows看得更清楚

把RS.GetRows看得更清楚
收藏 0 赞 0 分享

ASP面向对象编程探讨及比较

ASP面向对象编程探讨及比较
收藏 0 赞 0 分享

ASP错误处理

ASP错误处理
收藏 0 赞 0 分享

web文件管理器的后续开发

web文件管理器的后续开发
收藏 0 赞 0 分享

上一篇,下一篇过程代码

上一篇,下一篇过程代码
收藏 0 赞 0 分享

一小偷类!!有兴趣的可以看看

一小偷类!!有兴趣的可以看看
收藏 0 赞 0 分享
查看更多