ISO8601的VBScript [英] VBScript ISO8601
本文介绍了ISO8601的VBScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在VBScript中,确实的FormatDateTime
拥有ISO 8601的支持?
如果不是,怎么会我写这样的功能呢?
例如:
回复于FormatAsISO8601(第05/04/2011#)功能FormatAsISO8601(日期时间)
...
结束功能
解决方案
下面是具体的code,我从克里斯的类所需要的,有点更优化:
公共功能ToIsoDateTime(日期时间)
ToIsoDateTime = ToIsoDate(日期时间)及T&放大器; ToIsoTime(日期时间)及CurrentTimezone
结束功能公共职能ToIsoDate(日期时间)
ToIsoDate = CStr的(年(日期时间))及 - 与& StrN2(月(日期时间))及 - 与& StrN2(日(日期时间))
结束功能公共职能ToIsoTime(日期时间)
ToIsoTime = StrN2(小时(日期时间))及:&放大器; StrN2(分(日期时间))及:&放大器; StrN2(第二(日期时间))
结束功能专用功能StrN2(N)
如果len(CSTR(N))< 2然后StrN2 =0&放大器; ñ否则StrN2 = N
结束功能
In VBScript, does FormatDateTime
have ISO 8601 support?
If not, how would I write such function with it?
For example:
Response.Write FormatAsISO8601(#05/04/2011#)
Function FormatAsISO8601(datetime)
...
End Function
解决方案
Here is the specific code I needed from Chris' class, a bit more optimized:
Public Function ToIsoDateTime(datetime)
ToIsoDateTime = ToIsoDate(datetime) & "T" & ToIsoTime(datetime) & CurrentTimezone
End Function
Public Function ToIsoDate(datetime)
ToIsoDate = CStr(Year(datetime)) & "-" & StrN2(Month(datetime)) & "-" & StrN2(Day(datetime))
End Function
Public Function ToIsoTime(datetime)
ToIsoTime = StrN2(Hour(datetime)) & ":" & StrN2(Minute(datetime)) & ":" & StrN2(Second(datetime))
End Function
Private Function StrN2(n)
If Len(CStr(n)) < 2 Then StrN2 = "0" & n Else StrN2 = n
End Function
这篇关于ISO8601的VBScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文