JavaScript Tips


日付・時間を求める


日付や時間を求めるのにはDateオブジェクトを使用します。
getYearメソッドは2000年迄は西暦の下2桁を、2000年移行では4桁を返します。
getFullyearメソッドは常に西暦4桁を返しますがIE4,NN4以上でないと使えません。
<SCRIPT language="JavaScript">
<!--
_date=new Date();
_Fullyear =_date.getFullYear();
_year =_date.getYear();
_month=_date.getMonth()+1;
_day =_date.getDate();
_hours=_date.getHours();
_minutes=_date.getMinutes();
_seconds=_date.getSeconds();

document.write("getFullYear="+_Fullyear);
document.write("<BR>");
document.write("getYear="+_year);
document.write("<BR>");
document.write("getMonth="+_month);
document.write("<BR>");
document.write("getDate="+_day);
document.write("<BR>");
document.write("getHours="+_hours);
document.write("<BR>");
document.write("getMinutes="+_minutes);
document.write("<BR>");
document.write("getSeconds="+_seconds);
document.write("<BR>");

//-->
</SCRIPT>