時間の表示

Sample

タイプ1
アクセスした日時を日本風に表示

スクリプト
タイプ2
アクセスした日時をテキストボックス内に表示
スクリプト
タイプ3
アクセスした日時を英語で表示
スクリプト
タイプ4
リアルタイムに時刻を表示、日本向け
スクリプト
タイプ5
リアルタイムに時刻を表示、AM、PM表示
スクリプト

 

スクリプト(タイプ1)

<SCRIPT language="JavaScript"> <!-- nowtime=new Date()
japantime=new Date()
japantime.setTime(nowtime.getTime()+(nowtime.getTimezoneOffset()+540)*60*1000)
year=japantime.getYear()
month=new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月")
minutes=japantime.getMinutes()
hour=japantime.getHours()

   if(japantime.getYear()<2000){year="19"+year}
   if(japantime.getMinutes()<10){minutes="0"+minutes}
   if(hour>=12){
      inutes=minutes+"分"
}
if(hour>=12){
      hour-=12
      hour="日本時間 午後"+hour
}else{
      hour="日本時間 午前"+hour
} document.write("<FONT SIZE=2 color=#008000>",year,"年",month[japantime.getMonth()]," ",japantime.getDate(),"日/")
document.write("",hour,"時",minutes,"<br></font>")
// -->

</SCRIPT>
 
スクリプト(タイプ2)
<SCRIPT language="JavaScript">
<!--
nowtime=new Date()
japantime=new Date()
japantime.setTime(nowtime.getTime()+(nowtime.getTimezoneOffset()+540)*60*1000)
year=japantime.getYear()
minutes=japantime.getMinutes()
hour=japantime.getHours()
month=new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月")
if(japantime.getYear()<2000){year="19"+year}
if(japantime.getMinutes()<10){minutes="0"+minutes}
if(hour>=12){
minutes=minutes+"分"
}
if(hour>=12){
hour-=12
hour="日本時間 午後"+hour
}else{
hour="日本時間 午前"+hour
}
function jtbox(){
document.forms[0].elements[0].value="西暦"+year+"年"+month[japantime.getMonth()]+japantime.getDate()+"日/"+hour+"時"+minutes;
}
// -->

</SCRIPT>
 
スクリプト(タイプ3)
<SCRIPT language="JavaScript"> <!--
nowtime=new Date()
japantime=new Date()
japantime.setTime(nowtime.getTime()+(nowtime.getTimezoneOffset()+540)*60*1000)
year=japantime.getYear()
minutes=japantime.getMinutes()
hour=japantime.getHours()
month=new Array("Jan","Feb","Mar","Apr","May","Jun","July","Aug","Sep","Oct","Nov","Dec")

if(japantime.getYear()<2000){year="19"+year}
if(japantime.getMinutes()<10){minutes="0"+minutes}
if(hour>=12){
hour-=12
minutes=minutes+"P.M."
}else{
minutes=minutes+"A.M."
}
document.write("<FONT SIZE=4 color=green>",month[japantime.getMonth()]," ",japantime.getDate()," ",year)
document.write(" ",hour,":",minutes,",Japan time.","<BR></FONT>")
// -->

</SCRIPT>
 
スクリプト(タイプ4)
<body onLoad="Clock()" onUnload="clearTimeout(time_passed)">

<SCRIPT LANGUAGE="JavaScript">

<!--
document.write("<FORM METHOD=\"post\" NAME=\"indicator\"><INPUT TYPE=\"text\" NAME=\"time\" SIZE=\"22\"></FORM>");
function Clock() {
document.forms[0].elements[0].value=now();
time_passed=setTimeout("Clock()",1000);
}
function now() {
nowtime=new Date()
hour=nowtime.getHours()
min=nowtime.getMinutes()
sec=nowtime.getSeconds()
if (hour<12) {
ap="午前"
}else{
ap="午後"; hour=hour-12
}
if (min<10) {
min="0"+min
}
if (sec<10) {
sec="0"+sec
}
return ap+" "+hour+"時"+min+"分"+sec+"秒"
}
Clock()
//-->

</SCRIPT>
 
スクリプト(タイプ5)
<body onLoad="Clock()" onUnload="clearTimeout(time_passed)">

<SCRIPT LANGUAGE="JavaScript">

<!--
document.write("<FORM METHOD=\"post\" NAME=\"indicator\"><INPUT TYPE=\"text\" NAME=\"time\" SIZE=\"22\"></FORM>");
function Clock() {
document.forms[0].elements[0].value=now();
time_passed=setTimeout("Clock()",1000);
}
function now() {
nowtime=new Date()
hour=nowtime.getHours()
min=nowtime.getMinutes()
sec=nowtime.getSeconds()
if (hour<12) {
ap="AM :"
}else{
ap="PM :"; hour=hour-12
}
if (min<10) {
min="0"+min
}
if (sec<10) {
sec="0"+sec
}
return ap+" "+hour+" h "+min+" m "+sec+" s "
}
Clock()
//-->

</SCRIPT>