CSS > 新さっぽろ60+One

JavaScript

8.日付・時刻<59_204p>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>年、月、日、時、分、秒、ミリ秒を参照したい</title>
</head>
<body>
<p>■年、月、日、時、分、秒、ミリ秒を参照したい</p>
<script type="text/JavaScript">
<!--
today = new Date();
gggg = today.getFullYear();
gg = today.getYear();
mo = today.getMonth()+1;//実際の月より1少ないので注意
dd = today.getDate();
hh = today.getHours();
mn = today.getMinutes();
ss = today.getSeconds();
ms = today.getMilliseconds();
document.write("<p>現在の日時は<b>"+gggg+"年"+mo+"月"+dd+"日 "+hh+"時"+mn+"分"+ss+"秒"+ms+"ミリ秒</b>です。</p>");
document.write("<p>ちなみにgetYear()の値は「"+gg+"」です。</p>");
new_day = new Date("1999/12/31");
document.write("<p>1999年の場合getYear()の値は「"+new_day.getYear()+"」になります。</p>");
// -->
</script>
</body>
</html>


年、月、日、時、分、秒、ミリ秒を参照したい