Skip to content

Instantly share code, notes, and snippets.

@kureikei
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kureikei/2624de7a9406bb3b18e2 to your computer and use it in GitHub Desktop.
Save kureikei/2624de7a9406bb3b18e2 to your computer and use it in GitHub Desktop.
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