7+ C Sharp Clock Examples

This post contains a total of 7+ Hand-Picked C Sharp Clock Examples. All the clocks are made purely using C Sharp Programming Language.

You can use the source codes of these C# clocks for educational use with credits to the owner, if you need it for some other use then contact the owner.

Related Posts

Click a Code to Copy it, and Hover over a video to play it.

1. By ZΞ›RTHΞ›Π˜

C Sharp Clock by ZΞ›RTHΞ›Π˜. It is a world clock that displays the time of different cities from around the world. The cities used in this world clock are – Tokyo, Jakarta, Islamabad, Riyadh, London, Praia, Cayenne, Mexico City, Los Angeles. ( Source )

using System;
using System.Threading;
namespace WhatTimeIsIt
{
    class Program
    {
        static void PrintTyping(string input, bool newLine = true, int time = 100)
        {
            for(int i = 0; i < input.Length; i++)
            {
                Console.Write(input[i]);
                Thread.Sleep(time);
            }
            if(newLine == true)
                Console.WriteLine();
        }
        static void PrintAsciiClock(string input)
        {
            string[] asciiText = new string[input.Length];
            int asciiHeight = 5;
            int asciiWidth = 5;

            for(int i = 0; i < input.Length; i++)
            {
                switch(input[i])
                {
                    case '1':
                        asciiText[i] =
                            "   # "
                          + "   # "
                          + "   # "
                          + "   # "
                          + "   # ";
                        break;
                    case '2':
                        asciiText[i] =
                            " ####"
                          + "    #"
                          + " ####"
                          + " #   "
                          + " ####";
                        break;
                    case '3':
                        asciiText[i] =
                            " ####"
                          + "    #"
                          + " ####"
                          + "    #"
                          + " ####";
                        break;
                    case '4':
                        asciiText[i] =
                            " #  #"
                          + " #  #"
                          + " ####"
                          + "    #"
                          + "    #";
                        break;
                    case '5':
                        asciiText[i] =
                            " ####"
                          + " #   "
                          + " ####"
                          + "    #"
                          + " ####";
                        break;
                    case '6':
                        asciiText[i] =
                            " ####"
                          + " #   "
                          + " ####"
                          + " #  #"
                          + " ####";
                        break;
                    case '7':
                        asciiText[i] =
                            " ####"
                          + "    #"
                          + "    #"
                          + "    #"
                          + "    #";
                        break;
                    case '8':
                        asciiText[i] =
                            " ####"
                          + " #  #"
                          + " ####"
                          + " #  #"
                          + " ####";
                        break;
                    case '9':
                        asciiText[i] =
                            " ####"
                          + " #  #"
                          + " ####"
                          + "    #"
                          + " ####";
                        break;
                    case '0':
                        asciiText[i] =
                            " ####"
                          + " #  #"
                          + " #  #"
                          + " #  #"
                          + " ####";
                        break;
                    case ':':
                        asciiText[i] =
                            "     "
                          + "  #  "
                          + "     "
                          + "  #  "
                          + "     ";
                        break;
                }
            }
            string reArrange = string.Join("", asciiText);

            for(int i = 0; i < asciiHeight; i++)
            {
                for(int j = 0; j < input.Length; j++)
                {
                    for(int k = 0; k < asciiWidth; k++)
                    {
                        int index = i * ((j * input.Length) + k);
                        Console.Write(reArrange[(i * asciiWidth) 
                            + (j * (asciiHeight * asciiWidth)) + k]);
                    }
                }
                Console.WriteLine("");
            }
        }

        static void Main(string[] args)
        {
            // GMT sort descending
            int GMT = 9;
            string[] timeZone = {
                "Tokyo / Japan", 
                "Jakarta / Indonesia", 
                "Islamabad / Pakistan", 
                "Riyadh / Saudi Arabia", 
                "London / United Kingdom", 
                "Praia / Cape Verde", 
                "Cayenne / French Guiana",
                "Mexico City / Mexico", 
                "Los Angeles / United States"
            };

            for (int i = 0; i < timeZone.Length; i++)
            {
                TimeSpan offset = new TimeSpan(GMT, 00, 00);
                string standardName = timeZone[i];
                string displayGMT = " (GMT";
                
                if(GMT > 0)
                {
                    displayGMT += "+";
                }
                string displayName = timeZone[i] + displayGMT + GMT + ")";

                TimeZoneInfo country = TimeZoneInfo.CreateCustomTimeZone
                    (standardName, offset, displayName, standardName);

                string time = TimeZoneInfo.ConvertTime
                    (DateTime.Now, TimeZoneInfo.Local, country).ToString();

                for (int j = 0; j < time.Length; j++)
                {
                    if (time[j] == ' ')
                    {
                        time = time.Substring(j + 1);
                    }
                }
                Console.WriteLine(displayName);
                Console.WriteLine();
                PrintAsciiClock(time);
                Console.WriteLine();
                Console.WriteLine();
                GMT -= 2;
            }
        }
    }
}

2. By Nikolay Stepanchuk

Made by Nikolay Stepanchuk. The time updates automatically and displays the current time in different lines. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoloLearn {
    class Clock {
        static void Main() {
            string t;
            int seconds;
            DateTime dt = DateTime.Now;
            seconds = dt.Second;
            for(;;) {
                dt = DateTime.Now;
                if(seconds != dt.Second) {
                    seconds = dt.Second;
                    t = dt.ToString("T");
                    if(dt.Minute == 0 && dt.Second == 0)
                    t = t + "\a";
                    Console.WriteLine(t);
                }
            }
        }
    }
}

3. By Nicolas Limberger Ferreira

Made by Nicolas Limberger Ferreira. The clock displays the date, time and day. ( Source )

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)
        {
            var d = DateTime.Now; 
            var r = "Today is {0}, {1}";
            Console.WriteLine(string.Format(r, d, d.DayOfWeek));
        }
    }
}

4. By MrYulik

Made by MrYulik. It displays the date and the time. ( Source )

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)
        {
            while(true)
            {
                Console.WriteLine(DateTime.Now);
                System.Threading.Thread.Sleep(1000);
                Console.Clear();
            }
        }
    }
}

5. By Natalie

A little bit advance C Sharp clock by Natalie. You get the option to select what value you want to see, like if you want to see the current time then enter ‘3’ as input and press enter. There are also different values you can see like date, year etc. ( Source )

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)
        {    DateTime now=DateTime.Now;
            
            Console.WriteLine("Please enter the value of the option you want.");
            
            //options.
            Console.WriteLine ("1. Short Date");
            Console.WriteLine ("2. Long Date");
            Console.WriteLine ("3. Short Time");
            Console.WriteLine ("4. Long Time");
            Console.WriteLine ("5. Full Date/Time");
            Console.WriteLine ("6. Full Date/Time+seconds");
            Console.WriteLine ("7. Month+day");
            Console.WriteLine ("8. Month+year");
            Console.WriteLine ("9. Day Number");
            Console.WriteLine ("10. Day name");
            Console.WriteLine ("11. Hour(0-23)");
            Console.WriteLine ("12. Minute");
            Console.WriteLine ("13. Second");
            Console.WriteLine ("14. Year");
            
            try{
            int option=Convert.ToInt32(Console.ReadLine());
            
            switch(option){
            
            case 1:
            Console.WriteLine ("\nYou have picked 'Short Date.'");
            Console.WriteLine ("{0:d}",now);
            break;
            
            case 2:
            Console.WriteLine("\nYou have picked 'Long Date.'");
            Console.WriteLine("{0:D}",now);
            break;
            
            case 3:
            Console.WriteLine ("\nYou have picked 'Short Time.'");
            Console.WriteLine ("{0:t}",now);
            break;
            
            case 4:
            Console.WriteLine ("\nYou have picked 'Long Time.'");
            Console.WriteLine ("{0:T}",now);
            break;
            
            case 5:
            Console.WriteLine ("\nYou have picked 'Full Date/Time.'");
            Console.WriteLine ("{0:f}",now);
            break;
            
            case 6:
            Console.WriteLine ("\nYou have picked 'Full Date/Time+seconds.'");
            Console.WriteLine ("{0:F}",now);
            break;
            
            case 7:
            Console.WriteLine ("\nYou have picked 'Month+day.'");
            Console.WriteLine ("{0:M}",now);
            break;
            
            case 8:
            Console.WriteLine ("\nYou have picked 'Month+year.'");
            Console.WriteLine ("{0:Y}",now);
            break;
            
            case 9:
            Console.WriteLine ("\nYou have picked 'Day number.'");
            Console.WriteLine ("{0:dd}",now);
            break;
            
            case 10:
            Console.WriteLine ("\nYou have picked 'Day name.'");
            Console.WriteLine ("{0:dddd}",now);
            break;
            
            case 11:
            Console.WriteLine ("\nYou have picked 'Hour(0-23).'");
            Console.WriteLine ("{0:HH}",now);
            break;
            
            case 12:
            Console.WriteLine ("\nYou have picked 'Minute.'");
            Console.WriteLine ("{0:mm}",now);
            break;
            
            case 13:
            Console.WriteLine ("\nYou have picked 'Second.'");
            Console.WriteLine ("{0:ss}",now);
            break;
            
            case 14:
            Console.WriteLine ("\nYou have picked 'Year.'");
            Console.WriteLine ("{0:YYYY}",now);
            break;
            
            default:
            Console.WriteLine ("\nPlease pick a valid option.");
                break;
            }
            
            }
            catch(Exception e){
                Console.WriteLine ("\nPlease enter a whole number.(no decimals.)");
            }
        }
    }
}

6. By Piotr

Roman Clock by Piotr. This clock displays the time in Roman Numerals. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace RomanClock
{
    class Program
    { 
        static string Roman(int n) 
        {
            if(n<0&&n>59)throw new Exception("Too big value!");
            if(n>=50)return("L" + Roman(n-50));
            if(n>=40)return("XL" + Roman(n-40));
            if(n>=10)return("X" + Roman(n-10));
            if(n>=9)return("IX" + Roman(n-9));
            if(n>=5)return("V" + Roman(n-5));
            if(n>=4)return("IV" + Roman(n-4));
            if(n>=1)return("I" + Roman(n-1));
            else return(String.Empty);
        }
        static void Main(string[] args)
        { 
            Regex num = new Regex(@"\d{1,2}"); 
            DateTime curr = DateTime.Now; 
            MatchCollection mc = num.Matches(curr.ToShortTimeString()); 
            foreach(Match m in mc)
            {
                int a;
                int.TryParse(m.ToString(),out a); 
                Console.WriteLine(Roman(a));
            } 
            Console.WriteLine(curr.ToShortTimeString().Substring(curr.ToShortTimeString().Length-2)); 
            Console.WriteLine("INFO: First row->hour\nSecond row->minute.\nCode by Piotr Ptak"); 
            /* if you want to check another time change line 27 and create another DateTime obj.IMPORTANT! DateTime is reference type */
        }
    }
}

7. By Mehmet Batin

Made by Mehmet Batin. The clock displays time and date. ( Source )

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)
        {
            DateTime tarih = DateTime.Now;
            Console.WriteLine(tarih);
        }
    }
}

8. By MineMaster1999

Made by MineMaster1999. A simple C# clock that looks like digital clock. ( Source )

########## ##########   ########## ##########   ####################
##      ## ##      ##   ##       # ##      ##   ##       ######## ##
# ###### # # ###### #   # ##### ## # ###### #   # ##### ####### # ##
# ###### # # ###### # # ###### ### # ###### # # ###### ####### ## ##
# ###### # ##      ##   ##### #### ##       #   ##### ####### ### ##
# ###### # # ###### #   ### ###### ######## #   ### ######## #### ##
# ###### # # ###### # # ## ####### ######## # # ## ########       ##
# ###### # # ###### #   #        # # ###### #   #        ######## ##
##      ## ##      ##   #        # ##      ##   #        ######## ##
########## ##########   ########## ##########   ####################
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace SoloLearn
{
    class Program
    {
        static string[] r1 = new string[10] { "##########", "##########", "##########", "##########", "##########", "##########", "##########", "##########", "##########", "##########" };
        static string[] r2 = new string[10] { "##      ##", "####  ####", "##       #", "##      ##", "####### ##", "#        #", "##      ##", "#        #", "##      ##", "##      ##" };
        static string[] r3 = new string[10] { "# ###### #", "### # ####", "# ##### ##", "# ###### #", "##### # ##", "# ########", "# ###### #", "######## #", "# ###### #", "# ###### #" };
        static string[] r4 = new string[10] { "# ###### #", "## ## ####", "###### ###", "######## #", "#### ## ##", "#       ##", "# ########", "####### ##", "# ###### #", "# ###### #" };
        static string[] r5 = new string[10] { "# ###### #", "##### ####", "##### ####", "######## #", "### ### ##", "######## #", "#       ##", "###### ###", "##      ##", "##       #" };
        static string[] r6 = new string[10] { "# ###### #", "##### ####", "### ######", "###      #", "## #### ##", "######## #", "# ###### #", "##### ####", "# ###### #", "######## #" };
        static string[] r7 = new string[10] { "# ###### #", "##### ####", "## #######", "######## #", "#       ##", "######## #", "# ###### #", "#### #####", "# ###### #", "######## #" };
        static string[] r8 = new string[10] { "# ###### #", "##### ####", "#        #", "# ###### #", "####### ##", "# ###### #", "# ###### #", "### ######", "# ###### #", "# ###### #" };
        static string[] r9 = new string[10] { "##      ##", "##### ####", "#        #", "##      ##", "####### ##", "##      ##", "##      ##", "## #######", "##      ##", "##      ##" };
        static string[] r10 = new string[10] { "##########", "##########", "##########", "##########", "##########", "##########", "##########", "##########", "##########", "##########" };

        static void Main(string[] args)
        {
            //THIS METHOD GIVES YOU TIME ONCE
            Time_static();
            //THIS METHOD DYNAMICALLY UPDATES TIME (DOES NOT WORK ON THIS PAGE, IF YOU WANT TO RUN THIS PROGRAM USE ANOTHER IDE (LIKE VISUAL STUDIO))
            //Time_dynamic();
        }

        static void Time_static()
        {
            int[] minute = new int[2];
            int[] hour = new int[2];
            int[] second = new int[2];
            DateTime data = DateTime.Now;
            if (data.Hour <= 9)
            {
                hour[0] = 0;
                hour[1] = data.Hour;
            }
            else
            {
                hour[0] = data.Hour / 10;
                hour[1] = data.Hour % 10;
            }

            if (data.Minute <= 9)
            {
                minute[0] = 0;
                minute[1] = data.Minute;
            }
            else
            {
                minute[0] = data.Minute / 10;
                minute[1] = data.Minute % 10;
            }
            if (data.Second <= 9)
            {
                second[0] = 0;
                second[1] = data.Second;
            }
            else
            {
                second[0] = data.Second / 10;
                second[1] = data.Second % 10;
            }
            Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r1[hour[0]], r1[hour[1]], r1[minute[0]], r1[minute[1]], r1[second[0]], r1[second[1]]);
            Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r2[hour[0]], r2[hour[1]], r2[minute[0]], r2[minute[1]], r2[second[0]], r2[second[1]]);
            Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r3[hour[0]], r3[hour[1]], r3[minute[0]], r3[minute[1]], r3[second[0]], r3[second[1]]);
            Console.WriteLine("{0} {1} # {2} {3} # {4}{5}", r4[hour[0]], r4[hour[1]], r4[minute[0]], r4[minute[1]], r4[second[0]], r4[second[1]]);
            Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r5[hour[0]], r5[hour[1]], r5[minute[0]], r5[minute[1]], r5[second[0]], r5[second[1]]);
            Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r6[hour[0]], r6[hour[1]], r6[minute[0]], r6[minute[1]], r6[second[0]], r6[second[1]]);
            Console.WriteLine("{0} {1} # {2} {3} # {4}{5}", r7[hour[0]], r7[hour[1]], r7[minute[0]], r7[minute[1]], r7[second[0]], r7[second[1]]);
            Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r8[hour[0]], r8[hour[1]], r8[minute[0]], r8[minute[1]], r8[second[0]], r8[second[1]]);
            Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r9[hour[0]], r9[hour[1]], r9[minute[0]], r9[minute[1]], r9[second[0]], r9[second[1]]);
            Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r10[hour[0]], r10[hour[1]], r10[minute[0]], r10[minute[1]], r10[second[0]], r10[second[1]]);
        }

        static void Time_dynamic()
        {
            int[] minute = new int[2];
            int[] hour = new int[2];
            int[] second = new int[2];
            for (int a = 1; a > 0;)
            {
                Console.Clear();
                DateTime data = DateTime.Now;
                if (data.Hour <= 9)
                {
                    hour[0] = 0;
                    hour[1] = data.Hour;
                }
                else
                {
                    hour[0] = data.Hour / 10;
                    hour[1] = data.Hour % 10;
                }

                if (data.Minute <= 9)
                {
                    minute[0] = 0;
                    minute[1] = data.Minute;
                }
                else
                {
                    minute[0] = data.Minute / 10;
                    minute[1] = data.Minute % 10;
                }
                if (data.Second <= 9)
                {
                    second[0] = 0;
                    second[1] = data.Second;
                }
                else
                {
                    second[0] = data.Second / 10;
                    second[1] = data.Second % 10;
                }
                Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r1[hour[0]], r1[hour[1]], r1[minute[0]], r1[minute[1]], r1[second[0]], r1[second[1]]);
                Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r2[hour[0]], r2[hour[1]], r2[minute[0]], r2[minute[1]], r2[second[0]], r2[second[1]]);
                Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r3[hour[0]], r3[hour[1]], r3[minute[0]], r3[minute[1]], r3[second[0]], r3[second[1]]);
                Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r4[hour[0]], r4[hour[1]], r4[minute[0]], r4[minute[1]], r4[second[0]], r4[second[1]]);
                Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r5[hour[0]], r5[hour[1]], r5[minute[0]], r5[minute[1]], r5[second[0]], r5[second[1]]);
                Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r6[hour[0]], r6[hour[1]], r6[minute[0]], r6[minute[1]], r6[second[0]], r6[second[1]]);
                Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r7[hour[0]], r7[hour[1]], r7[minute[0]], r7[minute[1]], r7[second[0]], r7[second[1]]);
                Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r8[hour[0]], r8[hour[1]], r8[minute[0]], r8[minute[1]], r8[second[0]], r8[second[1]]);
                Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r9[hour[0]], r9[hour[1]], r9[minute[0]], r9[minute[1]], r9[second[0]], r9[second[1]]);
                Console.WriteLine("{0} {1}   {2} {3}   {4}{5}", r10[hour[0]], r10[hour[1]], r10[minute[0]], r10[minute[1]], r10[second[0]], r10[second[1]]);
                Thread.Sleep(500);
            }
        }
    }
}