VBScript:FormatDateTime函数

此功能可帮助开发人员格式化并返回有效的日期和时间表达式。

语法

FormatDateTime(date,format) 

参数说明

  • date,一个必需参数。
  • format,一个可选参数。该值指定要使用的日期或时间格式。它可以采用以下值:
    • 0 = vbGeneralDate-默认值。
    • 1 = vbLongDate-返回日期。
    • 2 = vbShortDate-返回日期。
    • 3 = vbLongTime-返回时间。
    • 4 = vbShortTime-返回时间。

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         d = ("2020-08-15 20:25")
         document.write("Line 1 : " & FormatDateTime(d) & " <br />")
         document.write("Line 2 : " & FormatDateTime(d,1) & "<br />")
         document.write("Line 3 : " & FormatDateTime(d,2) & "<br />")
         document.write("Line 4 : " & FormatDateTime(d,3) & "<br />")
         document.write("Line 5 : " & FormatDateTime(d,4) & "<br />")
       
      </script>
   </body>
</html>

将其另存为.html并在Internet Explorer中执行时,上述脚本将产生以下结果:

Line 1 : 15/08/2020 8:25:00 PM 
Line 2 : Thursday, 15 August 2020
Line 3 : 15/08/2020
Line 4 : 8:25:00 PM
Line 5 : 20:25

作者:terry,如若转载,请注明出处:https://www.web176.com/vbscript/1147.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2020年12月7日 下午3:42
下一篇 2020年12月7日 下午3:49

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注