爱生活

记录下生活点滴

一个时间格式的函数,可以把时间格式为各种输出

一个时间格式的函数,可以把时间格式为各种输出

<%
'一个时间格式的函数,可以把时间格式为各种输出
Function DateToStr(DateTime,ShowType)
 Dim DateMonth,DateDay,DateHour,DateMinute,DateWeek,DateSecond
 Dim FullWeekday,shortWeekday,Fullmonth,Shortmonth,TimeZone1,TimeZone2
 TimeZone1="+0800"
 TimeZone2="+08:00"
 FullWeekday=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
 shortWeekday=Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
Fullmonth=Array("January","February","March","April","May","June","July","August","September","October","November","December")
Shortmonth=Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

 DateMonth=Month(DateTime)
 DateDay=Day(DateTime)
 DateHour=Hour(DateTime)
 DateMinute=Minute(DateTime)
 DateWeek=weekday(DateTime)
 DateSecond=Second(DateTime)
 If Len(DateMonth)<2 Then DateMonth="0"&DateMonth
 If Len(DateDay)<2 Then DateDay="0"&DateDay
 If Len(DateMinute)<2 Then DateMinute="0"&DateMinute
 Select Case ShowType
 Case "Y-m-d"
  DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay
 Case "Y-m-d H:I A"
  Dim DateAMPM
  If DateHour>12 Then
   DateHour=DateHour-12
   DateAMPM="PM"
  Else
   DateHour=DateHour
   DateAMPM="AM"
  End If
  If Len(DateHour)<2 Then DateHour="0"&DateHour
  DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute&" "&DateAMPM
 Case "Y-m-d H:I:S"
  If Len(DateHour)<2 Then DateHour="0"&DateHour
  If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
  DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute&":"&DateSecond
 Case "YMDHIS"
  DateSecond=Second(DateTime)
  If Len(DateHour)<2 Then DateHour="0"&DateHour
  If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
  DateToStr=Year(DateTime)&DateMonth&DateDay&DateHour&DateMinute&DateSecond
 Case "YM"
  DateToStr=Right(Year(DateTime),2)&DateMonth
 Case "D"
  DateToStr=DateDay
Case "YMD"
DateToStr=Right(Year(DateTime),4)&DateMonth&DateDay
Case "MDY"
Dim DayEnd
select Case DateDay
Case 1
DayEnd="st"
Case 2
DayEnd="nd"
Case 3
DayEnd="rd"
Case Else
DayEnd="th"
End Select
DateToStr=Fullmonth(DateMonth-1)&" "&DateDay&DayEnd&" "&Right(Year(DateTime),4)
Case "w,d m y H:I:S"
  DateSecond=Second(DateTime)
  If Len(DateHour)<2 Then DateHour="0"&DateHour
  If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
DateToStr=shortWeekday(DateWeek-1)&","&DateDay&" "& Left(Fullmonth(DateMonth-1),3) &" "&Right(Year(DateTime),4)&" "&DateHour&":"&DateMinute&":"&DateSecond&" "&TimeZone1
Case "y-m-dTH:I:S"
  If Len(DateHour)<2 Then DateHour="0"&DateHour
  If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
  DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&"T"&DateHour&":"&DateMinute&":"&DateSecond&TimeZone2
 Case Else
  If Len(DateHour)<2 Then DateHour="0"&DateHour
  DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute
 End Select
End Function

'调用方式,当用下面的字符串格式时,就显示该时间格式
'[Y-m-d][Y-m-d H:I A][Y-m-d H:I:S][YMDHIS][YM][d][YMD][MDY]
response.Write DateToStr(now(),"w,d m y H:I:S")
%>

阅读更多
文章标签: timezone function sun
个人分类: asp
上一篇利用表格的属性style=&quot;&quot;display: none&quot;&quot;来显示或隐藏表格
下一篇一个数字转换为中文的函数
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭