58同城哈尔滨租房网站:电脑编程,谁来给我翻译一下这个function过程的???

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/04 15:48:31
function DateTimeFormat(DateTime,Format)
select case Format
case "1"
DateTimeFormat=""&year(DateTime)&"年"&month(DateTime)&"月"&day(DateTime)&"日"
case "2"
DateTimeFormat=""&month(DateTime)&"月"&day(DateTime)&"日"
case "3"
DateTimeFormat=""&year(DateTime)&"/"&month(DateTime)&"/"&day(DateTime)&""
case "4"
DateTimeFormat=""&month(DateTime)&"/"&day(DateTime)&""
case "5"
DateTimeFormat=""&month(DateTime)&"月"&day(DateTime)&"日 "&FormatDateTime(DateTime,4)&""
case "6"
temp="周日,周一,周二,周三,周四,周五,周六"
temp=split(temp,",")
DateTimeFormat=temp(Weekday(DateTime)-1)
case else
DateTimeFormat=DateTime
end select
end function
最好能说的详细点,我是刚学编程的不是很懂

function DateTimeFormat(DateTime,Format)
'时间格式化函数,参数:DataTime,时间类型,Format:格式
select case Format
case "1"
DateTimeFormat=""&year(DateTime)&"年"&month(DateTime)&"月"&day(DateTime)&"日"
'如果Format值为1,格式化成如:2006年7月12日
case "2"
DateTimeFormat=""&month(DateTime)&"月"&day(DateTime)&"日"
'如果Format值为2,格式化成如:7月12日
case "3"
DateTimeFormat=""&year(DateTime)&"/"&month(DateTime)&"/"&day(DateTime)&""
'如果Format值为3,格式化成如:2006/7/12
case "4"
DateTimeFormat=""&month(DateTime)&"/"&day(DateTime)&""
'如果Format值为4,格式化成如:7/12
case "5"
DateTimeFormat=""&month(DateTime)&"月"&day(DateTime)&"日 "&FormatDateTime(DateTime,4)&""
'如果Format值为5,格式化成如:7月12日 09:25
case "6"
temp="周日,周一,周二,周三,周四,周五,周六"
'字符串分隔的星期
temp=split(temp,",")
'将字符串转化成数组并保存进temp中
DateTimeFormat=temp(Weekday(DateTime)-1)
'Weekday(DateTime):如果是星期日,返回1,星期一返回2,所以要 - 1,获取在temp中的下标,从而获取相应下标的数组元素的值
case else
DateTimeFormat=DateTime
'否则,不进行格式化
end select
end function
'function 有返回值,传回的返回值保存进变量就行了,而这个变量必须和函数名相同,如:DateTimeFormat

一个日期格式转换的function
format参数为1到6的时候,分别按照不同的格式返回

否则就直接返回原有的格式

DateTimeFormat(日期数据,格式参数)

日期数据DateTime:要转换的日期,如转当前时间:now()
格式参数Format: 其有1到6种格式
第1种: 2006-7-1 1:1:1 -转换后->> 2006年7月1日
第2种: 2006-7-1 1:1:1 -转换后->> 7月1日
第3种: 2006-7-1 1:1:1 -转换后->> 2006/7/1
第4种: 2006-7-1 1:1:1 -转换后->> 7/1
第5种: 2006-7-1 1:1:1 -转换后->> 7月1日7/1
第6种: 2006-7-1 1:1:1 -转换后->> 周六
其他格式参数的则返回原有的格式