This post contains a total of 7+ C Sharp Calendar Program Examples with Source Code. All these Calendar Programs are made using C Sharp.
You can use the source code of these examples with credits to the original owner.
Related Posts
C Sharp Calendar Programs
1. C# Print Calendar Of Some Year
Made by Chill. Source
2002 2002 YEAR CALENDAR Jan Su Mo Tu We Th Fr St 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Feb Su Mo Tu We Th Fr St 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
printCalendarOfSomeYear();
}
static void printCalendarOfSomeYear()
{
string month;
int firstDayOfMonth;
bool leapYear;
int year;
try
{
year = Int32.Parse(Console.ReadLine()); //Get the number of the year from the user
}
catch (Exception)
{
Console.WriteLine("Error, you had input invalid year number.");
year = 2016;
}
Console.WriteLine ("{0} YEAR CALENDAR", year);
Console.WriteLine ();
leapYear = ((year%400 == 0)||((year%4 == 0)&&(year%100 != 0))) ? true : false; //Define is year leap or not
DateTime myDate = new DateTime(year, 01, 01);
DateTime operationalDate = new DateTime(); //some Date object to work with
//Print every month calendar
for (int i = 0; i<12; i++)
{
operationalDate = myDate.AddMonths(i);
month = operationalDate.ToString("MMM", CultureInfo.InvariantCulture);
printMonthAndWeekDayName(month);
firstDayOfMonth = (int) operationalDate.DayOfWeek; //Define what day of a week is first day of month
printDaysOfMonth (firstDayOfMonth, i, leapYear);
Console.WriteLine();
}
}
static void printMonthAndWeekDayName(string month)
{
Console.WriteLine("{0} Su Mo Tu We Th Fr St", month); //Print head of every month calendar
}
static void printDaysOfMonth(int firstDayOfMonth, int monthNum, bool leapYear)
{
int daysQuantity = 0;
int dayNumber = 0;
//Define days quantity in month
switch (++monthNum)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
daysQuantity = 31;
break;
case 4:
case 6:
case 9:
case 11:
daysQuantity = 30;
break;
case 2:
if (leapYear)
{daysQuantity = 29;}
else
{daysQuantity = 28;}
break;
}
int numberOfWeeks = 0;
//Define how many weeks there are in month
if ((daysQuantity + firstDayOfMonth) % 7 > 0)
{
numberOfWeeks = ((daysQuantity + firstDayOfMonth) / 7) + 1;
}
else
{
numberOfWeeks = (daysQuantity + firstDayOfMonth) / 7;
}
for (int k = 1; k <= numberOfWeeks; k++)
{
Console.Write ("{0}", createWhiteSpaces (firstDayOfMonth, k));
int j = 1;
if (k == 1) {j = firstDayOfMonth + 1;}
while ((j <= 7) && (dayNumber<daysQuantity))
{
j++;
dayNumber++;
if (dayNumber < 10) Console.Write ("0");
Console.Write ("{0} ", dayNumber);
}
Console.WriteLine();
}
}
static string createWhiteSpaces (int firstDayOfMonth, int weekNumber)
{
string blankSpace = "";
if (weekNumber == 1)
{
for (int m = 0; m < (6 + (firstDayOfMonth*3)); m++)
{
blankSpace += " ";
}
}
else
{
blankSpace = " ";
}
return blankSpace;
}
}
}
2. Calendar For This Month
Made by Jafca. Source
M T W T F S S 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int daysCount = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
Console.WriteLine("M\tT\tW\tT\tF\tS\tS");
int Gami = (int) new DateTime(DateTime.Now.Year,DateTime.Now.Month, 1).DayOfWeek;
Console.Write(new String('\t', Gami - 1));
for(int Challenge = 1; Challenge <= daysCount; ++Challenge)
{
Console.Write(Challenge.ToString("D2"));
if(Gami%7==0)
Console.Write("\n");
else
Console.Write("\t");
Gami++;
}
}
}
}
3. Persian Calendar
Made by iBahman. Source
1401/6/26
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//ابتدا برای استفاده از کلاس PersianCalendar می بایست namespace مربوطه رو اضافه کنید که این کلاس در فضای نام System.Globalization; قرار دارد .
using System.Globalization;
namespace ArtasSoft
{
class Program
{
static void Main(string[] args)
{
//ابتدا یک نمونه از کلاس باز سازی میکنیم .
PersianCalendar pc = new PersianCalendar ();
//تاریخ زمان حال میلادی را در متغیر dt قرار میدهیم .
DateTime dt = DateTime.Now;
//با متد های زیر به ترتیب سال ،ماه ،روز را تبدیل به تاریخ شمسی میکنیم .
Console.WriteLine (pc.GetYear(dt) + "/" + pc.GetMonth(dt) + "/" + pc.GetDayOfMonth(dt));
}
}
}
4. C# Simple Calendar
Made by Piotr. Source
It is year 2022 month 9 hour 15:01 1:Thursday 2:Friday 3:Saturday 4:Sunday 5:Monday 6:Tuesday 7:Wednesday 8:Thursday 9:Friday 10:Saturday 11:Sunday 12:Monday 13:Tuesday 14:Wednesday 15:Thursday 16:Friday ------------------------------ |Today is 17>>260 day of year| ------------------------------ 18:Sunday 19:Monday 20:Tuesday 21:Wednesday 22:Thursday 23:Friday 24:Saturday 25:Sunday 26:Monday 27:Tuesday 28:Wednesday 29:Thursday 30:Friday
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//simple calendar created using C# soon i ll add some new features. Hit upvote if U like it.
namespace CSharpCalendar
{
class Program
{
static StringBuilder Today(int i)
{
StringBuilder stp = new StringBuilder();
string a = $"|Today is {i}>>{DateTime.UtcNow.DayOfYear} day of year|";
stp.AppendLine(String.Join("",Enumerable.Repeat("-",a.Length)));
stp.AppendLine(a);
stp.AppendLine(String.Join("",Enumerable.Repeat("-",a.Length)));
return(stp);
}
static void Main(string[] args)
{
int i = 0;
int month = 0;
int year = 0;
int day = 0;
List <int> mon = new List<int> ();
List <int> tue = new List<int> ();
List <int> wed = new List<int> ();
List <int> thu = new List<int> ();
List <int> fri = new List<int> ();
List <int> sat = new List<int> ();
List <int> sun = new List<int> ();
object [] daysinweek = {mon,tue,wed,thu,fri,sat,sun};
foreach(var a in DateTime.Today.ToShortDateString().Split('/'))
{
if(i==0)
month=int.Parse(a);
if(i==1)
day=int.Parse(a);
if(i==2)
year=int.Parse(a);
i++;
}
Console.WriteLine($"It is year {year} month {month} hour {DateTime.Now.ToShortTimeString()}");
for(int k = 1;k<=DateTime.DaysInMonth(year,month);k++)
{
if(k==day)
{
Console.Write(Today(k));
}
else
{
Console.WriteLine($"{k}:{new DateTime(year,month,k).ToLongDateString().Substring(0,new DateTime(year,month,k).ToLongDateString().IndexOf(','))}");
}
}
}
}
}
5. Persian Calendar in C#
Made by sajjad toomari. Source
1401/6/26 15:2:34
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
DateTime dateTime = new DateTime();
PersianCalendar dateTimeP = new PersianCalendar();
dateTime = DateTime.Now;
Console.WriteLine(dateTimeP.GetYear(dateTime).ToString() + "/" + dateTimeP.GetMonth(dateTime) + "/" + dateTimeP.GetDayOfMonth(dateTime));
Console.WriteLine(dateTimeP.GetHour(dateTime) + ":" + dateTimeP.GetMinute(dateTime) + ":" + dateTimeP.GetSecond(dateTime));
}
}
}
6. Chinese calendar
Made by Alexey Sharuk. Source
2003 You were born in the year of the sheep.
using System;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
string[] name = new string[]
{
"monkey", "rooster", "dog", "pig", "rat", "bull",
"tiger", "rabbit", "dragon", "snake", "horse", "sheep"
};
int year = int.Parse(Console.ReadLine());
Console.WriteLine("You were born in the year of the {0}.", name[year % 12]);
}
}
}
7. 2021 Calendar
Made by William Ainley. Source
Year 2021 january mo tu we th fr sa su 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 febuary mo tu we th fr sa su 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
public class calender {
public int[] week = new int[7];
public int feb = 0;
public string[] week_copy = new string[7];
public int element = 0;
public int duplicate = 1;
public void month(int days, string month) {
element = 0;
duplicate = 1;
Console.Write(" ");
Console.Write(month);
Console.Write("\n");
week[element] = duplicate;
if (month == "febuary") {
feb++;
if (feb % 4 == 0) {
days = 29;
}
}
week_copy[0] = "mo";
week_copy[1] = "tu";
week_copy[2] = "we";
week_copy[3] = "th";
week_copy[4] = "fr";
week_copy[5] = "sa";
week_copy[6] = "su";
Console.Write(" ");
Console.Write(week_copy[0]);
Console.Write(" ");
Console.Write(week_copy[1]);
Console.Write(" ");
Console.Write(week_copy[2]);
Console.Write(" ");
Console.Write(week_copy[3]);
Console.Write(" ");
Console.Write(week_copy[4]);
Console.Write(" ");
Console.Write(week_copy[5]);
Console.Write(" ");
Console.Write(week_copy[6]);
Console.WriteLine("\n");
for (int x = 1; x < days + 1; x++) {
if (x < 10) {
Console.Write(" 0{0}", x, " ");
}
else {
Console.Write(" {0}", x, " ");
}
if (duplicate > 7) {
duplicate = 0;
}
if (x == 21 || x == 14) {
Console.Write("\n");
duplicate = 0;
}
if (duplicate >= 7) {
Console.WriteLine("");
}
element++;
duplicate++;
if (element > 6) {
element = 0;
}
}
Console.WriteLine("\n");
}
public void year(int year) {
Console.WriteLine("Year {0}", year);
Console.WriteLine("");
month(31, "january");
month(28, "febuary");
month(31, "march");
month(30, "april");
month(31, "may");
month(30, "june");
month(31, "july");
month(31, "august");
month(30, "september");
month(31, "october");
month(30, "november");
month(31, "december");
}
public void decade() {
for (int x = 2021; x < 2031; x++) {
year(x);
}
}
}
class Program
{
static void Main(string[] args)
{
calender year1 = new calender();
year1.decade();
}
}
}
8. Simple C# Calendar
Made by Lebedev Igor. Source
09/17/2022 15:06:09 09/17/2022 00:00:00 09.2022 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(DateTime.Now);
Console.WriteLine(DateTime.Today);
string data = Convert.ToString(DateTime.Today);
string mesyac = data.Substring(0, 2) + "." + data.Substring(6, 4);
int mesyac1 = Convert.ToInt32(data.Substring(0, 2));
int mesyac2 = Convert.ToInt32(data.Substring(6, 4));
int dney_in_mesyace = DateTime.DaysInMonth(mesyac2, mesyac1);
Console.WriteLine(mesyac);
for(int den = 1; den <= dney_in_mesyace; den++)
{
if(den < 10)
{
Console.Write(den + " ");
}
else
{
Console.Write(den + " ");
}
if(den % 7 == 0)
{
Console.WriteLine();
}
}
}
}
}