匯入 ASP常用函式 FormatDate

2022-03-24 21:23:50 字數 4323 閱讀 3818

<%

function formatdate(sdatetime, sreallydo)

dim sjorkin

sjorkin = getlocale()

if not isdate(sdatetime)

then sdatetime = now()

sdatetime = cdate(sdatetime)

select case ucase(sreallydo & "")

case

"0",

"1",

"2",

"3",

"4"formatdate = formatdatetime(sdatetime, sreallydo)

case

"00"

formatdate = formatdate(sdatetime,

"yyyy-mm-dd hh:mm:ss"

)case

"01"

formatdate = formatdate(sdatetime,

"yyyy年mm月dd日"

)case

"02"

formatdate = formatdate(sdatetime,

"yyyy-mm-dd"

)case

"03"

formatdate = formatdate(sdatetime,

"hh:mm:ss"

)case

"04"

formatdate = formatdate(sdatetime,

"hh:mm"

)case

"iso8601"

, "google"

, "sitemap"

'//iso8601格式, 一般用於googlesitemap, "+08:00" 為時區.

formatdate = formatdate(sdatetime,

"yyyy-mm-ddthh:mm:ss.000+08:00"

)case

"rfc822"

, "rss"

, "feed"

'//rfc822格式, 一般用於rss, "+0800" 為時區.

setlocale(

"en-gb"

)formatdate = formatdate(sdatetime,

"ew, dd emm yyyy hh:mm:ss +0800"

)setlocale(sjorkin)

case

"rnd"

, "rand"

, "randomize"

'//隨機字串

randomize

sjorkin = rnd()

formatdate = formatdate(sdatetime,

"yyyymmddhhmmss"

) & _

fix((

9 * 10^

6 -1) * sjorkin) + 10^

6case else

formatdate = sreallydo

formatdate = replace(formatdate,

"yyyy"

, year(sdatetime))

formatdate = replace(formatdate,

"dd"

, right(

"0"

& day(sdatetime), 2))

formatdate = replace(formatdate,

"hh"

, right(

"0"

& hour(sdatetime), 2))

formatdate = replace(formatdate,

"mm"

, right(

"0"

& minute(sdatetime), 2))

formatdate = replace(formatdate,

"ss"

, right(

"0"

& second(sdatetime), 2))

formatdate = replace(formatdate,

"yy"

, right(year(sdatetime), 2))

formatdate = replace(formatdate,

"d", day(sdatetime))

formatdate = replace(formatdate,

"h", hour(sdatetime))

formatdate = replace(formatdate,

"m", minute(sdatetime))

formatdate = replace(formatdate,

"s", second(sdatetime))

if instr(

1, formatdate,

"ew", 1

) >

0 then

setlocale(

"en-gb"

)formatdate = replace(formatdate,

"ew"

, ucase(weekdayname(weekday(sdatetime),

false

)))formatdate = replace(formatdate,

"ew"

, weekdayname(weekday(sdatetime),

false

))formatdate = replace(formatdate,

"ew"

, ucase(weekdayname(weekday(sdatetime),

true

)))formatdate = replace(formatdate,

"ew"

, weekdayname(weekday(sdatetime),

true

))setlocale(sjorkin)

else

formatdate = replace(formatdate,

"w", weekdayname(weekday(sdatetime),

false

))formatdate = replace(formatdate,

"w", weekdayname(weekday(sdatetime),

true

))end if

if instr(

1, formatdate,

"emm", 1

) >

0 then

setlocale(

"en-gb"

)formatdate = replace(formatdate,

"emm"

, monthname(month(sdatetime),

false

))formatdate = replace(formatdate,

"emm"

, monthname(month(sdatetime),

true

))setlocale(sjorkin)

else

formatdate = replace(formatdate,

"mm"

, right(

"0"

& month(sdatetime), 2))

formatdate = replace(formatdate,

"m", month(sdatetime))

end if

end select

end function

%>

<%

'將日期格式化為iso8601格式

response.write(formatdate(

"2008-03-06 08:03:06"

, "sitemap"

))'將日期格式化為rfc822格式

response.write(formatdate(

"2008-03-06 08:03:06"

, "rss"

))'將日期格式化為(英星期, 英月/日/年)

response.write(formatdate(now(),

"ew, emm/dd/yyyy"

))'將生成乙個以年月日時分秒隨機數的字串

response.write(formatdate(now(),

"rnd"

))%>

asp常用函式

array function 返回乙個陣列 syntax array list arguments 字元,數字均可 example dim myarray for i 1 to 7 redim preserve myarray i myarray i weekdayname i next resul...

asp常用函式

set jmail server.createobject jmail.tpmail 建立乙個jmail物件 jmail.silent true jmail不會丟擲例外錯誤,返回的值為false跟true jmail.logging true 啟用使用日誌 jmail.charset gb2312 ...

Asp 常用函式

textarea顯示用 function htmlencode1 fstring if fstring and not isnull fstring then fstring replace fstring,fstring replace fstring,fstring replace fstrin...