时间格式 [英] Time Format
本文介绍了时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当从
中拉出小时(或分钟,或秒,或日,或月等)服务器时: br />
<%=小时(时间)%>
有没有快速的方法(比如,没有if then语句来检查它和
修复它)格式化它所以它代表两位数字的所有小时,如:
00
上午12点。而不只是:
0
?
谢谢。
Hi,
When pulling the hour (or minute, or second, or day, or month, etc) from
the server like:
<%= hour(time) %>
Is there a quick way (like, without an if then statement to check it and
fix it) to format it so it represents all hours in two digits like:
00
for 12 am. instead of just:
0
?
Thanks.
推荐答案
嗨。
看看函数FormatDateTime():
http://msdn.microsoft.com /library/de...atdatetime.asp
Travis Pupkin写道:
Hi.
Take a look at function FormatDateTime():
http://msdn.microsoft.com/library/de...atdatetime.asp
Travis Pupkin wrote:
<%= hour(time)%>
是否有一种快速的方式(比如,没有if then语句来检查它并
修复它)来格式化它所以它代表两个数字的所有小时,如:
<%= hour(time) %>
Is there a quick way (like, without an if then statement to check it and
fix it) to format it so it represents all hours in two digits like:
-
Kai Boenke,QI / LBS-Hi
Robert Bosch GmbH Hildesheim
--
Kai Boenke, QI/LBS-Hi
Robert Bosch GmbH Hildesheim
遗憾的是,FormatDateTime不会做你想要的,也不会是
FormatCurrency等。
你可能会坚持创建一个小功能返回格式化的
字符串例如。
函数AddExtraZerosIfReq(plngValue)
Dim pstrValue
Dim plngChars
Dim i
pstrValue = CStr(plngValue)
plngChars = Len(pstrValue)
如果plngChars< ; 2然后
对于i = 1到plngChars步骤-1
pstrValue =" 0" &安培; pstrValue
下一页
结束如果
AddExtraZerosIfReq = pstrValue
结束功能
并将其引用为:
<%= AddExtraZerosIfReq(小时(时间))%>
注意:这会在Visual Basic中很简单,它将是:
格式(时间,00)
为什么他们错过了这个明显的功能VBScript超越我!
希望这会有所帮助,
克里斯。
" Kai Boenke" < KA ******** @ de.bosch.com>在消息中写道
news:bn ********** @ ns2.fe.internet.bosch.com ...
嗨。
看看函数FormatDateTime():
http://msdn.microsoft.com/library/de...atdatetime.asp
Travis Pupkin写道:
It''s a pity that FormatDateTime won''t do what you want, nor will
FormatCurrency etc.
You''re probably stuck with creating a small function to return the formatted
string eg.
Function AddExtraZerosIfReq(plngValue)
Dim pstrValue
Dim plngChars
Dim i
pstrValue = CStr(plngValue)
plngChars = Len(pstrValue)
If plngChars < 2 Then
For i = 1 to plngChars Step -1
pstrValue = "0" & pstrValue
Next
End If
AddExtraZerosIfReq = pstrValue
End Function
And referencing it as:
<%= AddExtraZerosIfReq(Hour(time)) %>
NB: This would be easy in Visual Basic, it would be:
Format(time, "00")
Why they missed this obvious functionality from VBScript is beyond me!
Hope this helps,
Chris.
"Kai Boenke" <ka********@de.bosch.com> wrote in message
news:bn**********@ns2.fe.internet.bosch.com...
Hi.
Take a look at function FormatDateTime():
http://msdn.microsoft.com/library/de...atdatetime.asp
Travis Pupkin wrote:
<%= hour(time)%>
有没有快捷方式(比如,没有if then语句)检查它并确定它来格式化它所以它代表两个数字的所有小时,如:
<%= hour(time) %>
Is there a quick way (like, without an if then statement to check it and
fix it) to format it so it represents all hours in two digits like:
-
Kai Boenke,QI / LBS-Hi
罗伯特博世有限公司希尔德斯海姆
--
Kai Boenke, QI/LBS-Hi
Robert Bosch GmbH Hildesheim
或者更简单<%= Right(''0''& ;小时(时间()),2)%>
HTH
克里斯
Or more simply <%=Right(''0'' & Hour(Time()),2)%>
HTH
Chris
>
这篇关于时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文