JavaScriptは常に内蔵対象(二)
1680 ワード
<script language="javascript">
// Date
var today = new Date();
alert(today);
//
var todayStr = today.toString();
alert(todayStr);
//
var todayLocal = today.toLocaleString();
alert(todayLocal);
//
var date = today.getDate();
alert(date);
//
var day = today.getDay();
alert(day);
// (0--11)
var month = today.getMonth();
alert(month);
//
var year = today.getFullYear();
alert(year);
</script>
一つの時計の例
<html>
<head>
<script language="javascript">
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// 10 0
m=checkTime(m);
s=checkTime(s);
document.getElementById('clock').innerHTML=h+":"+m+":"+s;
// 500 startTime
t=setTimeout('startTime()',500);
}
function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
</script>
<body>
<div id="clock"></div>
<button value=" " onclick="startTime(); return false;"> </button>
</body>
</html>