| 情報学部 | 菅沼ホーム | 目次 | 索引 |
プログラム(下がそのソースコード)は,各メソッドの使用例である.
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Date</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<META NAME=viewport CONTENT="width=device-width, initial-scale=1">
<LINK REL="stylesheet" TYPE="text/css" HREF="../../../master.css">
</HEAD>
<BODY CLASS="white">
<H1 STYLE="text-align: center">Date オブジェクト</H1>
<SCRIPT TYPE="text/javascript">
let now = new Date();
document.writeln("<DL>");
document.writeln("<DT>現在時刻等の取得");
document.writeln("<DD>現在時刻( toLocaleString ): " + now.toLocaleString());
document.writeln("<DD>現在時刻(UTC)( toUTCString ): " + now.toUTCString());
document.writeln("<DD>グリニッジ標準時( toGMTString ): " + now.toGMTString());
document.writeln("<DD>時差(分)( getTimezoneOffset ): " + now.getTimezoneOffset());
document.writeln("<DD>年( getYear ): " + now.getYear());
document.writeln("<DD>年(4桁)( getFullYear ): " + now.getFullYear());
document.writeln("<DD>年(UTC)( getUTCFullYear ): " + now.getUTCFullYear());
document.writeln("<DD>月(0~11)( getMonth ): " + now.getMonth());
document.writeln("<DD>月(0~11,UTC)( getUTCMonth ): " + now.getUTCMonth());
document.writeln("<DD>日( getDate ): " + now.getDate());
document.writeln("<DD>日(UTC)( getUTCDate ): " + now.getUTCDate());
document.writeln("<DD>曜日(0:日~6:土)( getDay ): " + now.getDay());
document.writeln("<DD>曜日(0:日~6:土,UTC)( getUTCDay ): " + now.getUTCDay());
document.writeln("<DD>時間( getHours ): " + now.getHours());
document.writeln("<DD>時間(UTC)( getUTCHours ): " + now.getUTCHours());
document.writeln("<DD>分( getMinutes ): " + now.getMinutes());
document.writeln("<DD>分(UTC)( getUTCMinutes ): " + now.getUTCMinutes());
document.writeln("<DD>秒( getSeconds ): " + now.getSeconds());
document.writeln("<DD>秒(UTC)( getUTCSeconds ): " + now.getUTCSeconds());
document.writeln("<DD>ミリ秒( getMilliseconds ): " + now.getMilliseconds());
document.writeln("<DD>ミリ秒(UTC)( getUTCMilliseconds ): " + now.getUTCMilliseconds());
document.writeln("<DD>経過秒数(ミリ秒)( getTime ): " + now.getTime());
document.writeln("<DT>指定した時間までの経過秒数");
document.writeln("<DD>経過秒数(ミリ秒)( parse ): " + Date.parse("2006/2/17:9:36:0"));
document.writeln("<DT>時間の設定");
now = new Date("jan 1, 2020 12:00:00");
document.writeln("<DD>修正前(jan 1, 2020 12:00:00): " + now.toLocaleString());
now.setYear(2001);
now.setFullYear(2001);
now.setMonth(1);
now.setDate(2);
now.setHours(13);
now.setMinutes(1);
now.setSeconds(2);
document.writeln("<DD>修正後(feb 2, 2001 13:01:02): " + now.toLocaleString());
now.setUTCFullYear(2001);
now.setUTCMonth(1);
now.setUTCDate(2);
now.setUTCHours(13);
now.setUTCMinutes(1);
now.setUTCSeconds(2);
document.writeln("<DD>修正後(feb 2, 2001 13:01:02,UTC): " + now.toLocaleString());
document.writeln("</DL>");
</SCRIPT></BODY>
</HTML>
| 情報学部 | 菅沼ホーム | 目次 | 索引 |