Vbscript-formatdatetime-function

提供:Dev Guides
移動先:案内検索

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 = ("2013-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>

lとして保存してInternet Explorerで実行すると、上記のスクリプトは次の結果を生成します-

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