師匠の散歩Grandmaster Wander

JavaScriptのかけら7

その他メソッド

Date

日付の関数。世界標準時と日本時間の9時間のずれを意識するのに注意すること。UNIXのエポック秒は秒単位だったのに対し、こちらはミリ秒で得られる。

var today = new Date();
document.write("today = " + today +"\n");
var birthday = new Date('December 17, 1995 03:24:00');
document.write("birthday = " + birthday +"\n");
var birthday = new Date('1995-12-17T03:24:00');
document.write("birthday = " + birthday +"\n");
var birthday = new Date(1995, 11, 17);
document.write("birthday = " + birthday +"\n");
var birthday = new Date(1995, 11, 17, 3, 24, 0);
document.write("birthday = " + birthday +"\n");
var thatday = new Date(1970,  0,  1, 0, 0, 0);
document.write("thatday = " + thatday +"\n");
var thatday = new Date(1969,  0,  0, 0, 0, 0);
document.write("thatday = " + thatday +"\n");
document.write("getTime() = " + today.getTime() +"\n");
document.write( "Date.parse(today) " +  Date.parse(today) + " /ミリ秒が0でセットされているのに注意する\n" );
document.write("today.getTime() = " + today.getTime() +" /協定世界時 (UTC) 1970 年 1 月 1 日 00:00:00 から与えられた日時までの間のミリ秒単位の数 \n");
var today = new Date();
var gregory = "1970/1/1 9:0:0";
var year,month,date,hour,minute,second,week;
year=today.getFullYear();
month=today.getMonth() + 1;
date=today.getDate();
hour=today.getHours();
minute=today.getMinutes();
second=today.getSeconds();
week=today.getDay();
var weeks = [ "日","月","火","水","木","金","土"];
document.write( year + "/" + month + "/" + date + " " + hour +":" + minute +":"+ second +"(" + weeks[week] + ") / 各項目で書き出す \n" );
// week=1 == Monday / week=0 == Sunday


Topに戻る // 一覧に戻る
Copyright(C) Grandmaster since 2010 最終更新:20120/2/10