700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > html用vbscript显示当前日期 VBS日期(时间)格式化函数代码

html用vbscript显示当前日期 VBS日期(时间)格式化函数代码

时间:2020-01-10 12:38:07

相关推荐

html用vbscript显示当前日期 VBS日期(时间)格式化函数代码

核心代码

currenttimestr1 = cstr(year(now()))&"-"&right("0"&month(now()),2)&"-"&right("0"&day(now()),2)&" "&right("0"&hour(now()),2)&":"&right("0"&minute(now()),2)&":"&right("0"&minute(now()),2)

currenttimestr2 = cstr(year(now()))&"-"&right("0"&month(now()),2)&"-"&right("0"&day(now()),2)

wscript.echo currenttimestr1 '-04-11 15:57:57

wscript.echo currenttimestr2 '-04-11

'格式化时间方法 n_flag(1-5)

wscript.echo format_time(now(),5)

function format_time(s_time, n_flag)

dim y, m, d, h, mi, s

format_time = ""

if isdate(s_time) = false then exit function

y = cstr(year(s_time))

m = cstr(month(s_time))

if len(m) = 1 then m = "0" & m

d = cstr(day(s_time))

if len(d) = 1 then d = "0" & d

h = cstr(hour(s_time))

if len(h) = 1 then h = "0" & h

mi = cstr(minute(s_time))

if len(mi) = 1 then mi = "0" & mi

s = cstr(second(s_time))

if len(s) = 1 then s = "0" & s

select case n_flag

case 1

' yyyy-mm-dd hh:mm:ss

format_time = y & "-" & m & "-" & d & " "& h &":" & mi &":" & s

case 2

' yyyy-mm-dd

format_time = y & "-" & m & "-" & d

case 3

' hh:mm:ss

format_time = h & ":" & mi & ":" & s

case 4

' yyyy年mm月dd日

format_time = y & "年" & m & "月" & d & "日"

case 5

' yyyymmdd

format_time = y & m & d

end select

end function

vbscript下格式化时间和日期的函数

我们有时候遇到的日期格式可能是-1-12 ,系统自动将月份中的0去掉了,但是有时候我们需要完整的日期格式 ,如:-01-12 那么怎么办呢?下面的几个函数可以轻松搞定

'将一个一位的数字前面加零

function fillzero(str)

ttt=str

if len(str)=1 then

ttt="0" & str

end if

fillzero=ttt

end function

'转化日期,将 一位补上零 -1-2 --> -01-02

function convertdate(tdate)

ttt=tdate

if isdate(tdate) then

ttt=year(tdate) & "-" & fillzero(month(tdate)) & "-" & fillzero(day(tdate))

end if

convertdate=ttt

end function

'输入一个日期时间串,转换成年四位,其他两位的新的日期时间串

function convertdatetime(tdatetime)

ttt=tdatetime

if isdate(tdatetime) then

ttt=year(tdatetime) & "-" & fillzero(month(tdatetime)) & "-" & fillzero(day(tdatetime)) & " " & fillzero(cstr(hour(tdatetime))) & ":" & fillzero(cstr(minute(tdatetime))) & ":" & fillzero(cstr(second(tdatetime)))

end if

convertdatetime=ttt

end function

这篇文章就介绍到这了,需要的朋友可以参考一下。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。