文章摘要
本文介绍了Rem Pw_Sys中一个用于日期格式转换的函数DateTimeFormat,该函数通过不同的Format参数生成不同的日期和时间字符串。主要功能如下:
1. **格式代码**:支持多种格式代码("1"至"10"),可根据需求选择显示完整的日期、月份、日期与星期、时间等。
2. **显示内容**:
- 格式"1"至"7"显示年、月、日、星期、小时、分钟等信息,部分格式可选日期为零填充。
- 格式"8"显示月份和日期。
- 格式"9"显示小时和分钟。
- 格式"10"显示年、月。
3. **函数结构**:通过case语句根据Format参数选择合适的格式字符串,并在格式"6"中额外嵌入格式化时间。
4. **用途**:适用于不同场景的日期和时间格式转换,支持自定义输出方式。
文章详细列举了所有格式代码的显示内容和适用场景,适合需要灵活控制日期和时间格式的应用。
<%
Rem Pw_Sys 日期格式转换函数
function DateTimeFormat(DateTime,Format)
select case Format
case “1”
DateTimeFormat=””&year(DateTime)&”年”&month(DateTime)&”月”&Right(“0″ & Day(DateTime),2)&”日”
case “2”
DateTimeFormat=””&month(DateTime)&”月”&Right(“0″ & Day(DateTime),2)&”日”
case “3”
DateTimeFormat=””&year(DateTime)&”-“&month(DateTime)&”-“&Right(“0″ & Day(DateTime),2)&””
case “4”
DateTimeFormat=””&year(DateTime)&”/”&month(DateTime)&”/”&Right(“0″ & Day(DateTime),2)&””
case “5”
DateTimeFormat=””&month(DateTime)&”/”&Right(“0″ & Day(DateTime),2)&””
case “6”
DateTimeFormat=””&year(DateTime)&”年”&month(DateTime)&”月”&Right(“0” & Day(DateTime),2)&”日<font color=red> “&FormatDateTime(DateTime,4)&”</font>”
case “7”
temp=”星期日,星期一,星期二,星期三,星期四,星期五,星期六”
temp=split(temp,”,”)
DateTimeFormat=temp(WeekRight(“0” & Day(DateTime),2)-1)
case “8”
DateTimeFormat=””&month(DateTime)&”-“&Right(“0″ & Day(DateTime),2)&””
case “9”
if len(hour(DateTime))=1 then
str=”0″&hour(DateTime)
else
str=hour(DateTime)
end if
DateTimeFormat=DateTimeFormat(DateTime,1)&” “&str&”:”&Minute(DateTime)
case “10”
DateTimeFormat=””&year(DateTime)&”年”&month(DateTime)&”月”
case else
DateTimeFormat=DateTime
end select
end function
%>