<%
'功能:多功能日期格式化函数
'来源:http://jorkin.reallydo.com/article.asp?id=477
Function FormatDate(sDateTime, sReallyDo)
Dim sTmpString, sJorkin, i : sTmpString = ""
FormatDate = ""
sReallyDo = sReallyDo & ""
If Not IsDate(sDateTime) Then sDateTime = Now()
sDateTime = CDate(sDateTime)
Select Case UCase(sReallyDo)
Case "0", "1", "2", "3", "4"
FormatDate = FormatDateTime(sDateTime, sTmpString)
Case "ATOM", "ISO8601", "W3C", "SITEMAP"
FormatDate = Replace(FormatDate(sDateTime, "YYYY-MM-DD|HH:NN:SS+08:00"), "|", "T")
Case "COOKIE", "RFC822", "RFC1123", "RFC2822", "RSS"
FormatDate = FormatDate(sDateTime, "W, DD MMM YYYY HH:NN:SS +0800")
Case "RFC850", "RFC1036"
FormatDate = FormatDate(sDateTime, "WW, DD-MMM-YY HH:NN:SS +0800")
Case "RND", "RAND", "RANDOMIZE" '//随机字符串
Randomize
sJorkin = Rnd()
FormatDate = FormatDate(sDateTime, "YYYYMMDDHHNNSS") & _
Fix((9 * 10^7 -1) * sJorkin) + 10^7
Case Else
For i = 1 To Len(sReallyDo)
sJorkin = Mid(sReallyDo, i, 1)
If Right(sTmpString, 1) = sJorkin Or Right(sTmpString, 1) = "C" Or Right(sTmpString, 1) = "Z" Or Right(sTmpString, 1) = "U" Or Right(sTmpString, 1) = "E" Or Right(sTmpString, 1) = "J" Then
sTmpString = sTmpString & sJorkin
Else
FormatDate = FormatDate & FormatDateTimeString(sDateTime, sTmpString)
sTmpString = sJorkin
End If
Next
FormatDate = FormatDate & FormatDateTimeString(sDateTime, sTmpString)
End Select
End Function
%>
<%
'功能:多功能日期格式化函数
'来源:http://jorkin.reallydo.com/article.asp?id=477
Function FormatDateTimeString(sDateTime, sReallyDo)
Dim sLocale : sLocale = GetLocale()
SetLocale("en-gb")
Select Case sReallyDo
Case "YYYY" '// 4位数年
FormatDateTimeString = Year(sDateTime)
Case "YY" '// 2位数年
FormatDateTimeString = Right(Year(sDateTime), 2)
Case "CMMMM", "CMMM", "CMM", "CM" '// 中文月份名
SetLocale("zh-cn")
FormatDateTimeString = MonthName(Month(sDateTime))
Case "MMMM" '// 英文月份名(全)
FormatDateTimeString = MonthName(Month(sDateTime), False)
Case "MMM" '//英文月份名(缩)
FormatDateTimeString = MonthName(Month(sDateTime), True)
Case "MM" '// 月(补0)
FormatDateTimeString = Right("0" & Month(sDateTime), 2)
Case "M" '// 月
FormatDateTimeString = Month(sDateTime)
Case "JD" '// 日(加st nd rd th)
FormatDateTimeString = Day(sDateTime)
Select Case FormatDateTimeString
Case 1, 21, 31
FormatDateTimeString = FormatDateTimeString & "st"
Case 2, 22
FormatDateTimeString = FormatDateTimeString & "nd"
Case 3, 23
FormatDateTimeString = FormatDateTimeString & "rd"
Case Else
FormatDateTimeString = FormatDateTimeString & "th"
End Select
Case "DD" '// 日(补0)
FormatDateTimeString = Right("0" & Day(sDateTime), 2)
Case "D" '// 日
FormatDateTimeString = Day(sDateTime)
Case "HH" '// 小时(补0)
FormatDateTimeString = Right("0" & Hour(sDateTime), 2)
Case "H" '// 小时
FormatDateTimeString = Hour(sDateTime)
Case "NN" '// 分(补0)
FormatDateTimeString = Right("0" & Minute(sDateTime), 2)
Case "N" '// 分
FormatDateTimeString = Minute(sDateTime)
Case "SS" '//秒(补0)
FormatDateTimeString = Right("0" & Second(sDateTime), 2)
Case "S" '//秒
FormatDateTimeString = Second(sDateTime)
Case "CWW", "CW" '// 中文星期
SetLocale("zh-cn")
FormatDateTimeString = WeekdayName(Weekday(sDateTime))
Case "WW" '// 英文星期(全)
FormatDateTimeString = WeekdayName(Weekday(sDateTime), False)
Case "W" '// 英文星期(缩)
FormatDateTimeString = WeekdayName(Weekday(sDateTime), True)
Case "CT" '// 12小时制(上午/下午)
SetLocale("zh-tw")
FormatDateTimeString = FormatDateTime(sDateTime, 3)
Case "UT" '// 12小时制(AM/PM)
SetLocale("en-us")
FormatDateTimeString = FormatDateTime(sDateTime, 3)
Case "ET" '// 12小时制(a.m./p.m.)
SetLocale("es-ar")
FormatDateTimeString = FormatDateTime(sDateTime, 3)
Case "ZT" '// 12小时制(AM/PM)(补0)
SetLocale("en-za")
FormatDateTimeString = FormatDateTime(sDateTime, 3)
Case "T" '// 24小时制时间
FormatDateTimeString = FormatDateTime(sDateTime, 3)
Case Else
FormatDateTimeString = sReallyDo
End Select
SetLocale(sLocale)
End Function
%>
<%
'可以用到的参数
sString = ""
sString = sString & "YYYY-MM-DD HH:NN:SS<br />"
sString = sString & "YY-M-D H:N:S<br />"
sString = sString & "T<br />UT<br />ZT<br />CT<br />ET<br />"
sString = sString & "CMMMM CMMM MMMM MMM<br />"
sString = sString & "CWW WW W<br />JD"
Response.Write(FormatDate(Now(), sString) & "<hr />")
'将日期格式化为ATOM格式
Response.Write(FormatDate("2008-03-06 08:03:06", "ATOM") & "<hr />")
'将日期格式化为RSS格式
Response.Write(FormatDate("2008-03-06 08:03:06", "RSS") & "<hr />")
'将日期格式化为RFC850格式
Response.Write(FormatDate("2008-03-06 08:03:06", "RFC850") & "<hr />")
'将生成一个以年月日时分秒随机数的字符串
Response.Write(FormatDate(Now(), "RND") & "<hr />")
%>
其实ASP自带了好多格式
<%
aArray = Array("af", "sq", "ar-ae", "ar-bh", "ar-dz", "ar-eg", "ar-iq", "ar-jo", "ar-kw", "ar-lb", "ar-ly", "ar-ma", "ar-om", "ar-qa", "ar-sa", "ar-sy", "ar-tn", "ar-ye", "eu", "be", "bg", "ca", "zh-cn", "zh-hk", "zh-sg", "zh-tw", "hr", "cs", "da", "nl", "nl-be", "en-au", "en-bz", "en-ca", "en-ie", "en-jm", "en-nz", "en-za", "en-tt", "en-gb", "en-us", "et", "fa", "fi", "fo", "fr", "fr-be", "fr-ca", "fr-lu", "fr-ch", "gd", "de", "de-at", "de-li", "de-lu", "de-ch", "el", "he", "hi", "hu", "is", "in", "it", "it-ch", "ja", "ko", "lv", "lt", "mk", "ms", "mt", "no", "pl", "pt", "pt-br", "rm", "ro", "ro-mo", "ru", "ru-mo", "sr", "tn", "sl", "sk", "sb", "es", "es-ar", "es-bo", "es-cl", "es-co", "es-cr", "es-do", "es-ec", "es-gt", "es-hn", "es-mx", "es-ni", "es-pa", "es-pe", "es-pr", "es-py", "es-sv", "es-uy", "es-ve", "sx", "sv", "sv-fi", "th", "tr", "ts", "uk", "ur", "vi", "xh", "ji", "zu")
For j = 0 To UBound(aArray)
Response.Write(Locale(aArray(j)))
Next
aArray = Array("1078", "1052", "14337", "15361", "5121", "3073", "2049", "11265", "13313", "12289", "4097", "6145", "8193", "16385", "1025", "10241", "7169", "9217", "1069", "1059", "1026", "1027", "2052", "3076", "4100", "1028", "1050", "1029", "1030", "1043", "2067", "3081", "10249", "4105", "6153", "8201", "5129", "7177", "11273", "2057", "1033", "1061", "1065", "1035", "1080", "1036", "2060", "3084", "5132", "4108", "1084", "1031", "3079", "5127", "4103", "2055", "1032", "1037", "1081", "1038", "1039", "1057", "1040", "2064", "1041", "1042", "1062", "1063", "1071", "1086", "1082", "1044", "1045", "2070", "1046", "1047", "1048", "2072", "1049", "2073", "3098", "1074", "1060", "1051", "1070", "1034", "11274", "16394", "13322", "9226", "5130", "7178", "12298", "4106", "18442", "2058", "19466", "6154", "10250", "20490", "15370", "17418", "14346", "8202", "1072", "1053", "2077", "1054", "1055", "1073", "1058", "1056", "1066", "1076", "1085", "1077")
For j = 0 To UBound(aArray)
Response.Write(Locale(aArray(j)))
Next
Function Locale(s)
On Error Resume Next
Dim i
SetLocale(s)
Locale = ""
Locale = Locale & "<font color=red>" & s & "</font><br>"
For i = 0 To 4
Locale = Locale & FormatDateTime(Now, i)
Locale = Locale & "<br />"
Next
Locale = Locale & "<hr />"
If Err Then Locale = ""
End Function
%>