Skip to content

Instantly share code, notes, and snippets.

@kureikei
Last active Aug 29, 2015
Embed
What would you like to do?
static void Main(string[] args)
{
var t = DateTime.Today;
var offset = (int)t.AddDays(-t.Day + 1).DayOfWeek; // 曜日の取得
var count = DateTime.DaysInMonth(t.Year, t.Month); // 月の日数の取得
Console.Write(new string(' ', offset * 3)); // 1週目の余白
for (var i = 1; i <= count; i++)
{
Console.Write(i.ToString().PadLeft(2) + // 1桁の日の空白パディング処理と日の出力
(((i + offset) % 7 == 0 || i == count) ? "\n" : " ")); // 日と日の間の空白出力と各週と最終日の改行処理
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment