Hàm FormatDateTime trong VBScript


❮ Toàn bộ tài liệu tham khảo VBScript

Hàm FormatDateTime định dạng và trả về biểu thức ngày hoặc giờ hợp lệ.

Cú pháp

FormatDateTime(date,format)

Parameter Description
date Required. Any valid date expression (like Date() or Now())
format Optional. A value that specifies the date/time format to use

Can take the following values:

  • 0 = vbGeneralDate - Default. Returns date: mm/dd/yyyy and time if specified: hh:mm:ss PM/AM.
  • 1 = vbLongDate - Returns date: weekday, monthname, year
  • 2 = vbShortDate - Returns date: mm/dd/yyyy
  • 3 = vbLongTime - Returns time: hh:mm:ss PM/AM
  • 4 = vbShortTime - Return time: hh:mm

Thí dụ

Thí dụ

Hiển thị ngày ở các định dạng khác nhau:

<%

d=CDate("2019-05-31 13:45")
response.write(FormatDateTime(d) & "<br />")
response.write(FormatDateTime(d,1) & "<br />")
response.write(FormatDateTime(d,2) & "<br />")
response.write(FormatDateTime(d,3) & "<br />")
response.write(FormatDateTime(d,4) & "<br />")

%>

Đầu ra của đoạn mã trên sẽ là:

5/31/2019 1:45:00 PM
Friday, May 31, 2019
5/31/2019
1:45:00 PM
13:45

❮ Toàn bộ tài liệu tham khảo VBScript