Last active
January 30, 2023 08:16
-
-
Save Myoga1012/fa9712f81a00b03fd910 to your computer and use it in GitHub Desktop.
TypeScriptでカレンダーを出力するソースコードです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Visual StudioでそのTypeScriptファイルをビルドした時に生成されるJavaScriptコードです。 | |
window.onload = function () { | |
// 現在日を取得し、当月1日の曜日と末日を求めます。 | |
var now = new Date(); | |
var prePad = new Date(now.getFullYear(), now.getMonth(), 1).getDay(); | |
var lastDay = new Date(now.getFullYear(), now.getMonth() + 1, 0).getDate(); | |
// カレンダーを出力します。 | |
var el = document.getElementById('content'); | |
for (var curDay = -prePad + 1; curDay <= lastDay; curDay++) { | |
// 半角スペース1つ出力します。curDayが負の時はさらに2つ出力します。 | |
el.innerHTML += " " + (curDay < 1 ? " " : (curDay < 10 ? " " : "") + curDay.toString() + ((prePad + curDay) % 7 == 0) ? "<br/>" : ""); | |
} | |
}; | |
//# sourceMappingURL=app.js.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 名前 : Myoga Screw-bright (旧名:Myoga S. Tomonaka) | |
// Twitter : https://twitter.com/Myoga1012 | |
window.onload = () => { | |
// 現在日を取得し、当月1日の曜日と末日を求めます。 | |
var now: Date = new Date(); | |
var prePad: number = new Date( now.getFullYear(), now.getMonth(), 1 ).getDay(); | |
var lastDay: number = new Date( now.getFullYear(), now.getMonth() + 1, 0 ).getDate(); | |
// カレンダーを出力します。 | |
var el = document.getElementById( 'content' ); | |
for ( var curDay: number = -prePad + 1; curDay <= lastDay; curDay++ ) { | |
// 半角スペース1つ出力します。curDayが負の時はさらに2つ出力します。 | |
el.innerHTML += " " + ( curDay < 1 ? " " : | |
// curDayが正の時です。1桁なら半角スペースを1つ出力します。そして日付を出力します。 | |
( curDay < 10 ? " " : "" ) + curDay.toString() + | |
// 土曜日を出力したら、改行タグを入れます。 | |
( ( ( prePad + curDay ) % 7 == 0 ) ? "<br/>" : "" ) ); | |
} | |
}; | |
// Calendar.ts | |
// Copyright (c) 2014 Myoga-TN.net All Rights Reserved. | |
// This software is released under the MIT License. | |
// http://opensource.org/licenses/mit-license.php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HTMLではcontentのIDを持つタグのフォントは等幅フォントにしておきます。