Latest web development tutorials

VBScript FormatDateTime function

VBScript Reference Complete VBScript Reference

FormatDateTime function and returns a valid expression of the date or time.

grammar

FormatDateTime(date,format)

参数 描述
date 必需。任何有效的日期表达式(比如 Date() 或者 Now())。
format 可选。规定所使用的日期/时间格式的格式值。

可采用下面的值:

  • 0 = vbGeneralDate - 默认。返回日期:mm/dd/yy 及如果指定时间:hh:mm:ss PM/AM。
  • 1 = vbLongDate - 返回日期:weekday, monthname, year
  • 2 = vbShortDate - 返回日期:mm/dd/yy
  • 3 = vbLongTime - 返回时间:hh:mm:ss PM/AM
  • 4 = vbShortTime - 返回时间:hh:mm

Examples

Examples

Display the date in different formats:

<script type="text/vbscript">

d=CDate("2010-02-16 13:45")
document.write(FormatDateTime(d) & "<br />")
document.write(FormatDateTime(d,1) & "<br />")
document.write(FormatDateTime(d,2) & "<br />")
document.write(FormatDateTime(d,3) & "<br />")
document.write(FormatDateTime(d,4) & "<br />")

</script>

Examples of the above output:

2/16/2010 1:45:00 PM
Tuesday, February 16, 2010
2/16/2010
1:45:00 PM
13:45

try it"


VBScript Reference Complete VBScript Reference