Skip to content

Instantly share code, notes, and snippets.

@akirad
Last active December 24, 2015 00:09
Show Gist options
  • Save akirad/6715197 to your computer and use it in GitHub Desktop.
Save akirad/6715197 to your computer and use it in GitHub Desktop.
An easy sample to show current date and years of Heisei(平成).
<html>
<head>
<title>現在時刻</title>
<script language="JavaScript">
function getCurrentTime() {
var dayArray = new Array("日","月","火","水","木","金","土");
var dateObj = new Date();
var year = dateObj.getYear() + 1900;
var heisei = year - 1988;
var month = dateObj.getMonth() + 1;
var date = dateObj.getDate();
var day = dateObj.getDay();
var hour = dateObj.getHours();
var min = dateObj.getMinutes();
document.getElementById('date').innerHTML = year + "/" + month + "/" + date + "/" + "(" + dayArray[day] + ") " + hour + ":" + min;
document.getElementById('heisei').innerHTML = "平成" + heisei +"年です。";
}
</script>
</head>
<body onLoad="getCurrentTime()">
<div style="font-weight:bold;">現在時刻</div>
<div id="date"></div>
<div id="heisei"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment