17
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

javascriptで日付・曜日・時間を表示する方法

Last updated at Posted at 2014-05-11

javascriptで日付・曜日・時間を表示する方法

javascriptで日時を表示したい場合がたまにあるのでメモ。

■実装方法

bodyタグ内に以下のようにスクリプトを記述するだけでOK

<html>
<head></head>
<body>
<script language="JavaScript">
			<!--
				myTbl     = new Array("","","","","","","");
				myD       = new Date();
				
				myYear    = myD.getYear()
				myYear4   = (myYear < 2000) ? myYear+1900 : myYear;
				myMonth   = myD.getMonth() + 1;
				myDate    = myD.getDate();
				myDay     = myD.getDay();
				myHours   = myD.getHours();
				myMinutes = myD.getMinutes();
				mySeconds = myD.getSeconds();
				
				myMess1   = myYear4 + "" + myMonth + "" + myDate + "";
				myMess2   = myTbl[myDay] + "曜日";
				myMess3   = myHours + "" + myMinutes + "" + mySeconds + "";
				myMess    = myMess1 + " " + myMess2 + " " + myMess3;
				document.write( myMess );
			// -->
</script>
</body>
</html>

こんな感じで表示される。

karenn.png

以上、参考まで。


簡単家計簿 Androidアプリ

17
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?