hack のためのネタ帳, etc,,,

constructor のバリエーション

ローカルタイム指定

new Date(year, mon, day, hour, min, sec, msec); // mon = [0:11]
new Date("mm dd, yyyy HH:MM:SS"); // mm = [1:12]|"Jan"|"Feb"|...|"January"|"February"|...
new Date("yyyy/mm/dd HH:MM:SS");
new Date("mm/dd/yyyy HH:MM:SS");
new Date("yy/mm/dd HH:MM:SS");
new Date("mm/dd/yy HH:MM:SS");

タイムゾーン指定

new Date("yyyy/mm/dd HH:MM:SS GMT+zzzz");
new Date("yyyy/mm/dd HH:MM:SS GMT-zzzz");
new Date("yyyy/mm/dd HH:MM:SS UTC+zzzz");
new Date("yyyy/mm/dd HH:MM:SS UTC-zzzz");

UNIX time 指定

new Date(time);

methods

UNIX time ([msec]単位) の取得と設定

Date.parse(string);
Date.UTC(year, mon, day, hour, min, sec, msec); // mon = [0:11]
Date.prototype.getTime();
Date.prototype.setTime(time);

ローカルタイムの取得

Date.prototype.getFullYear();
Date.prototype.getYear();
Date.prototype.getMonth(); // [0:11]
Date.prototype.getDate();
Date.prototype.getDay();
Date.prototype.getHours();
Date.prototype.getMinutes();
Date.prototype.getSeconds();
Date.prototype.getMilliseconds();

ローカルタイムの設定

Date.prototype.setFullYear(year);
Date.prototype.setYear(year);
Date.prototype.setMonth(mon); // mon = [0:11]
Date.prototype.setDate(date);
Date.prototype.setHours(hour);
Date.prototype.setMinutes(min);
Date.prototype.setSeconds(sec);
Date.prototype.setMilliseconds(msec);

グローバルタイムの取得

Date.prototype.getUTCFullYear();
Date.prototype.getUTCYear();
Date.prototype.getUTCMonth(); // [0:11]
Date.prototype.getUTCDate();
Date.prototype.getUTCDay();
Date.prototype.getUTCHours();
Date.prototype.getUTCMinutes();
Date.prototype.getUTCSeconds();
Date.prototype.getUTCMilliseconds();

グローバルタイムの指定

Date.prototype.setUTCFullYear(year);
Date.prototype.setUTCYear(year);
Date.prototype.setUTCMonth(mon); // mon = [0:11]
Date.prototype.setUTCDate(date);
Date.prototype.setUTCHours(hour);
Date.prototype.setUTCMinutes(min);
Date.prototype.setUTCSeconds(sec);
Date.prototype.setUTCMilliseconds(msec);

タイムゾーン([min]単位)の取得

Date.prototype.getTimezoneOffset();

parse 可能なフォーマット

IE8
o 1970/01/01 00:00:00 GMT+0900
o 1970/01/01 00:00:00 UTC+0900
o 1970/01/01 00:00:00GMT+0900
o 1970/01/01 00:00:00UTC+0900
o 1970/01/01 00:00:00 +0900
o 1970/01/01 00:00:00+0900
x 1970-01-01 00:00:00+0900
x 1970-01-01T00:00:00+0900
x 1970/01/01 00:00:00 GMT+09:00
x 1970/01/01 00:00:00 UTC+09:00
x 1970-01-01 00:00:00+09:00
x 1970-01-01T00:00:00+09:00
x 19700101T000000UTC+0900
x 19700101T000000GMT+0900
x 19700101000000UTC+0900
x 19700101000000GMT+0900
x 19700101000000+0900
Forefox11
o 1970/01/01 00:00:00 GMT+0900
o 1970/01/01 00:00:00 UTC+0900
x 1970/01/01 00:00:00GMT+0900
x 1970/01/01 00:00:00UTC+0900
o 1970/01/01 00:00:00 +0900
x 1970/01/01 00:00:00+0900
x 1970-01-01 00:00:00+0900
o 1970-01-01T00:00:00+0900
o 1970/01/01 00:00:00 GMT+09:00
o 1970/01/01 00:00:00 UTC+09:00
x 1970-01-01 00:00:00+09:00
o 1970-01-01T00:00:00+09:00
x 19700101T000000UTC+0900
x 19700101T000000GMT+0900
x 19700101000000UTC+0900
x 19700101000000GMT+0900
x 19700101000000+0900

確認用コード

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

フリーエリア

管理人/副管理人のみ編集できます