ASP 将当前时间转换为字符串

来源:百度知道 编辑:UC知道 时间:2024/05/28 03:26:27
上传一个文件 想将上传的当前时间 转换成字符串作为上传之后的文件名
求解决方法
例 使用now()
获得2009-10-28 17:15:13
现在想将其变为 20091028171513 应该如何去做?

你不必要用now()这个函数的
给你举个例子吧:
前面日期数字符串:
Dim filename1, string2

<%
filesname1=Year(now)&Month(Now)&Date(Now)
Randomize '初始化随机种子
for i = 1 to 6
string2= string2 ∫(6*rnd)+1
next
filesname1= filesname1&string2
%>

asp没有现成的函数,只能自己自定义一个函数。

<%
Function FormatDTime(psDateTime)
Dim sDateTime
sDateTime =Year(psDateTime)
If Cint(Month(psDateTime)) <10 Then sDateTime =sDateTime &"0"
sDateTime =sDateTime & Month(psDateTime)
If Cint(Day(psDateTime)) <10 Then sDateTime =sDateTime &"0"
sDateTime =sDateTime & Day(psDateTime)
If Cint(Hour(psDateTime)) <10 Then sDateTime =sDateTime &"0"
sDateTime =sDateTime & Hour(psDateTime)
If Cint(Minute(psDateTime)) <10 Then sDateTime =sDateTime &"0"
sDateTime =sDateTime & Minute(psDateTime)
If Cint(Second(psDateTime)) <10 Then sDateTime =sDateTime &"