16+ CPP Clock Examples

This post contains a total of 16+ Hand-Picked C++ Clock Examples. All the Clocks are made purely using C++ Language.

You can use the source codes of these C++ Clocks for educational use with the credits to original owner, but if you need it for some other use then you should ask for the permission from its original owner.

Related Posts

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

1. By James Boblak

Made by James Boblak. To see the time of a certain region enter the time zone first. Like enter 5.5 for India. ( Source )


#include <iostream>
#include <iomanip>
#include <time.h>
using namespace std;

int main() { 

    float z=(0);  //time zone offset vs. GMT
    cin>>z;   //enter 5.5 for IST (India), for example
    cout<<"Difference from GMT: "<<z<<"\n";
    if(z>12)
      {z-=24;}  //corrects outputs for GMT+13-GMT+23
    int x=time(0);
    float y=x%86400;  //reveals seconds since midnight
    float time=y/3600;  //in hours
    int hour=(time)+z;  //removes decimal
    float m=(time-hour)+z;  //reveals decimal
    int min=m*60;  //converts decimal to whole minutes
    if (min<0)
      {min+=59,hour+=23;}  //keeps time zone corr. +
    string mer;
    if (hour<12)  //determines morning or afternoon
      {mer="am";}
      else
        {mer="pm";}
    if (hour==0)  //renames midnight from 0
      {hour=12;}  //to 12
    if (hour>12)  //converts 24h to 12h
      {hour-=12;} 
    std::cout<<"The time there is: "
      <<hour<<":"
      <<std::setfill('0') //makes 0 the placeholder digit
      <<std::setw(2) //keeps 2 digits in minutes
      <<min
      <<mer; 
    
    return 0;
}

2. By Babak

Basic C++ clock by Babak. The clock displays the time of different cities of the world along with a Clock Face. ( Source )

#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <ctime>
#include <map>
#include <sstream>
#include <string>
using namespace std;

#define R(n)   static_cast<int>(n < 0 ? n - 0.5 : n + 0.5)
class Constants {
public:

    // Constants related to clock's shape
    static constexpr int Size    = 41; // Must be odd
    static constexpr int MinRad  = Size / 3 + 1;
    static constexpr int HourRad = MinRad - 4;
    static constexpr int FaceRad = MinRad + 3;
    static const char hourMarks[];

    // Conversion constants
    static constexpr double FullPrd = 360.0;
    static constexpr double ToDeg   = M_PI / 180.0;
    static constexpr int    MinDeg  = 6;
    static constexpr int    HourDeg = MinDeg * 5;
    static constexpr double HourDiv = 15.0;

    // Time, timezone, and calendrical constants
    static constexpr time_t SecInHour = 3600;
    static constexpr time_t SecInHalf = SecInHour / 2;
    static constexpr int Noon         = 12;
    static constexpr int Year2018     = 2018;

    static const string strMonth[];
    static const string strWday[];

    static const string cityInfo[];
    static const time_t utcOffsets[];

    // Other constants
    static constexpr int NotSet      = -1;
    static constexpr time_t NoOffset = 0;
    static constexpr int W           = 2;
};

const char Constants::hourMarks[] = {
    '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', '1', '2'
};
const string Constants::strMonth[] = {
    "Jan", "Feb", "Mar", "Apr",
    "May", "Jun", "Jul", "Aug",
    "Sep", "Oct", "Nov", "Dec"
};
const string Constants::strWday[] = {
    "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
const string Constants::cityInfo[] = {
    "(UTC-08:00) Los Angeles",
    "(UTC-06:00) Mexico City",
    "(UTC-05:00) New York",
    "(UTC) London, Lisbon",
    "(UTC+01:00) Paris, Berlin, Madrid",
    "(UTC+03:00) Moscow",
    "(UTC+05:30) New Delhi",
    "(UTC+08:00) Beijing",
    "(UTC+09:00) Tokyo",
    "(UTC+10:00) Sydney"
};
const time_t Constants::utcOffsets[] = {
    SecInHour * (-8),
    SecInHour * (-6),
    SecInHour * (-5),
    SecInHour * 0,
    SecInHour * 1,
    SecInHour * 3,
    SecInHour * 5 + SecInHalf,
    SecInHour * 8,
    SecInHour * 9,
    SecInHour * 10,
};
class Tm {
public:
    static string getZonesInfo();
    static int getGmtHour();
    static int getGmtMin();
    static int getLocalHour();
    static int getLocalMin();

private:
    enum UTC {
        UTC_m08, UTC_m06, UTC_m05,
        UTC_00, // GMT
        UTC_p01, UTC_p03, UTC_p05_30, UTC_p08, UTC_p09, UTC_p10
    };
    enum Month {
        Jan, Feb, Mar, Apr,
        May, Jun, Jul, Aug,
        Sep, Oct, Nov, Dec
    };
    static const map<int, Month> month;

    static string getUtcDateTime(time_t offset, UTC zone);
    static void getLocalTime();
    static bool isDST(Month m, int day, UTC zone);
    static int gmtHour, gmtMin,
               localHour, localMin;
};

string Tm::getZonesInfo() {
    string fullInfo = "";
    for (int uti = UTC::UTC_m08; uti <= UTC_p10; ++uti) {
        fullInfo += Constants::cityInfo[uti] + "\n"
                    + getUtcDateTime(Constants::utcOffsets[uti],
                                     static_cast<UTC>(uti))
                    + "\n\n";

    }
    return fullInfo;
}
int Tm::getGmtHour() {
    if (gmtHour == Constants::NotSet)
        getUtcDateTime(Constants::NoOffset, UTC_00);
    return gmtHour;
}
int Tm::getGmtMin() {
    if (gmtMin == Constants::NotSet)
        getUtcDateTime(Constants::NoOffset, UTC_00);
    return gmtMin;
}
int Tm::getLocalHour() {
    if (localHour == Constants::NotSet)
        getLocalTime();
    return localHour;
}
int Tm::getLocalMin() {
    if (localMin == Constants::NotSet)
        getLocalTime();
    return localMin;
}
string Tm::getUtcDateTime(time_t offset, UTC zone) {
    time_t rawT = time(nullptr) + offset;
    struct tm *now   = gmtime(&rawT);

    // Save GMT hour and min for analog clock
    if (zone == UTC_00) {
        gmtHour = now->tm_hour;
        gmtMin  = now->tm_min;
    }

    bool isSummerTime = isDST(month.find(now->tm_mon)->second,
                                now->tm_mday, zone);

    if (isSummerTime) {
        rawT += Constants::SecInHour;
        now   = gmtime(&rawT);
    }

    // Store required data to convert to string
    string wday = Constants::strWday[now->tm_wday],
           mon  = Constants::strMonth[now->tm_mon];
    int mday    = now->tm_mday,
        year    = now->tm_year + 1900;

    if (year > Constants::Year2018)
        cout << "DST might be invalid. Please update dstBase.\n";


    int hour = now->tm_hour,
        min  = now->tm_min,
        sec  = now->tm_sec;

    // Build a string of all information
    stringstream sBuilder;
    sBuilder << "["
             << wday << " - " << mon  << " "
             << setw(Constants::W) << mday << ", " << year << " - "
             << setw(Constants::W) << hour << ":"
             << setw(Constants::W) << min  << ":"
             << setw(Constants::W) << sec << "]"
             << (isSummerTime ? "[DST]" : "");
    string info = sBuilder.str();
    return info;
}
void Tm::getLocalTime() {
    time_t rawT    = time(nullptr);
    struct tm *loc = localtime(&rawT);

    localHour      = loc->tm_hour;
    localMin       = loc->tm_min;
}
bool Tm::isDST(Month m, int day, UTC zone) {
    bool dst = false;
	if (zone > UTC_p01 && zone < UTC_p10) return dst; // Early handling non-dst zones -- bug fixed
	
    typedef map<UTC, pair<pair<Month, int>, pair<Month, int>>> dstBase;
    dstBase _2018 {
        // { zone, { {start date}, {end date} } }
        { UTC_m08, { {Mar, 11}, {Nov,  4} } },
        { UTC_m06, { {Apr,  1}, {Oct, 28} } },
        { UTC_m05, { {Mar, 11}, {Nov,  4} } },
        { UTC_00,  { {Mar, 25}, {Oct, 28} } },
        { UTC_p01, { {Mar, 25}, {Oct, 28} } },
        { UTC_p10, { {Oct,  7}, {Apr,  1} } },
    };

    auto record  = _2018.find(zone);
    Month startm = record->second.first.first,
            endm = record->second.second.first;
    int   startd = record->second.first.second,
            endd = record->second.second.second;

    // Since Sydney's DST is irregular and splits between 2 years, calculating its opposite (not dst) is much easier -- bug fixed
	if (record->first == UTC_p10) {
		if (m < startm || (m == startm && day < startd))
			if (m > endm || (m == endm && day > endd))
				dst = false;

		dst = true;
	}
	else {
		if (m > startm || (m == startm && day >= startd))
			if (m < endm || (m == endm && day <= endd))
				dst = true;

		dst = false;
	}
	return dst;
}
const map<int, Tm::Month> Tm::month {
    {0, Jan}, {1, Feb}, {2, Mar}, {3, Apr},
    {4, May}, {5, Jun}, {6, Jul}, {7, Aug},
    {8, Sep}, {9, Oct}, {10, Nov}, {11, Dec}
};
int Tm::gmtHour   = Constants::NotSet;
int Tm::gmtMin    = Constants::NotSet;
int Tm::localHour = Constants::NotSet;
int Tm::localMin  = Constants::NotSet;
class AnalogC {
public:
    AnalogC(int h, int m);

private:
    void initClock();
    void setFace();
    void setHands();
    void drawClock();

    char clock[Constants::Size][Constants::Size];
    int hour, min,
        center;
    bool isPM;
};

AnalogC::AnalogC(int h, int m) {
    if (h >= Constants::Noon) {
        isPM = true;
        if (h > Constants::Noon)
            hour = h - Constants::Noon;
        else
            hour = h;
    }
    else {
        hour = h;
        isPM = false;
    }
    min = m;

    initClock();
    setFace();
    setHands();
    drawClock();
}
void AnalogC::initClock() {

    // initialize the clock's background
    center = Constants::Size / 2;
    for (int i = 0; i < Constants::Size; ++i)
        for (int j = 0; j < Constants::Size; ++j) {
            if (i == center && j == center)
                clock[i][j] = 'O';
            else if (i == center &&
                     j == (center + center / 2)) {
                    char ap = 'A';
                    if (isPM) ap = 'P';
                    clock[i][j++] = '[';
                    clock[i][j++] = ap;
                    clock[i][j++] = 'M';
                    clock[i][j]   = ']';
            }
            else if ( (i == 0 || i == Constants::Size-1) ||
                      (j == 0 || j == Constants::Size-1) )
                clock[i][j] = 'X';
            else clock[i][j] = ' ';
        }
}
void AnalogC::setFace() {

    double x = 0,
           y = 0;
    int r = Constants::FaceRad,
        c = 0;

    for (double i = 0.0;
         i < Constants::FullPrd;
         i += Constants::MinDeg) {

        // adjusted to work in clock-wise fashion
        x = r * sin(i * Constants::ToDeg);
        y = r * cos(i * Constants::ToDeg);

        // every 30ยฐ put a clock number on the perimeter of the face
        if (!(static_cast<int>(i) % Constants::HourDeg))
            clock[R(x) + center][R(y) + center] = Constants::hourMarks[c++];
        else
            clock[R(x) + center][R(y) + center] = '*';
    }
}
void AnalogC::setHands() {

    int rm = Constants::MinRad,
        rh = Constants::HourRad,

        // minute hand's endpoint
        xmEnd = R( rm * sin((min * Constants::MinDeg)
                            * Constants::ToDeg) ),
        ymEnd = R( rm * cos((min * Constants::MinDeg)
                            * Constants::ToDeg) ),

        // hour hand's initial endpoint
        xhEnd = R( rh * sin((hour * Constants::HourDeg)
                            * Constants::ToDeg) ),
        yhEnd = R( rh * cos((hour * Constants::HourDeg)
                            * Constants::ToDeg) ),

        // hour hand's offset based on current minute
        hoffset = R(min / Constants::HourDiv),
        msteps, hsteps;

    if (abs(xmEnd) > abs(ymEnd)) msteps = abs(xmEnd);
    else msteps = abs(ymEnd);

    if (abs(xhEnd) > abs(yhEnd)) {
        hsteps = abs(xhEnd);

        switch (hour) {

        // quadrant 1 (q1)
        case 2:
            xhEnd += hoffset;
            yhEnd -= hoffset;
            break;
        case 3:
        case 4:
            xhEnd -= hoffset;
            yhEnd -= hoffset;
            break;

        // quadrant 3 (q3)
        case 8:
            xhEnd -= hoffset;
            yhEnd += hoffset;
            break;
        case 9:
        case 10:
            xhEnd += hoffset;
            yhEnd += hoffset;
            break;
        }
    }
    else {
        hsteps = abs(yhEnd);
        switch (hour) {

        // quadrant 4 (q4)
        case 11:
        case 12:
        case 0: // Damn! Midnight
        case 1:
            if (hour == 1 && min >= 30)
                yhEnd -= hoffset;
            xhEnd += hoffset;
            break;

        // quadrant 2 (q2)
        case 5:
        case 6:
        case 7:
            if (hour == 7 && min >= 30)
                yhEnd += hoffset;
            xhEnd -= hoffset;
            break;
        }
    }

    double xmInc = xmEnd / static_cast<double>(msteps),
           ymInc = ymEnd / static_cast<double>(msteps),
           xhInc = xhEnd / static_cast<double>(hsteps),
           yhInc = yhEnd / static_cast<double>(hsteps),
           xmNxt, ymNxt, xhNxt, yhNxt;

    xmNxt = ymNxt = xhNxt = yhNxt = center;

    // set minute hand
    for (int i = 0; i < msteps; ++i) {
        ymNxt += xmInc;
        xmNxt -= ymInc; // y-axis must be reversed since index increas from top to down unlike real cartesian system
        clock[R(xmNxt)][R(ymNxt)] = 'M';
    }

    // set hour hand
    for (int i = 0; i < hsteps; ++i) {
        yhNxt += xhInc;
        xhNxt -= yhInc;
        clock[R(xhNxt)][R(yhNxt)] = 'H';
    }
}
void AnalogC::drawClock() {
    for (int i = 0; i < Constants::Size; ++i) {
        for (int j = 0; j < Constants::Size; ++j)
            cout << clock[i][j];
        cout << endl;
    }
}
int main()
{
    cout << "    ***    Greenwich Mean Time    ***\n";
    AnalogC clk1(Tm::getGmtHour(), Tm::getGmtMin());
    //cout << "    ***     System Local Time     ***\n";
    //AnalogC clk2(Tm::getLocalHour(), Tm::getLocalMin());
    cout << "\n **  Time & Date all around the world  **\n\n";
    cout << Tm::getZonesInfo() << endl;
}

3. By Nicolas Turek

Made by Nicolas Turek. The clock displays the current time. ( Source )

#include <iostream>
#include <ctime>
using namespace std;

int main(){
     int x[3]{0,0,0};
     while(1){
        if(x[2]!=(time(0)%60)){
    x[0]=(time(0)%86400)/3600;
    x[1]=(time(0)%3600)/60;
    x[2]=time(0)%60;
    cout<<x[0]
        <<":"
        <<x[1]
        <<":"
        <<x[2]
        <<endl;
        }
     }
    return 0;
}

4. By Egor Guslyantsev

Made by Egor Guslyantsev. The clock displays the current time of your machine / your place. ( Source )

#include <iostream>
#include <ctime>
using namespace std;

int main() {
    int hours;
    int minutes;
    int seconds;
    unsigned long int last_time = time(0);
    while (true){
        if (time(0) > last_time){
            hours = (time(0) / 60 / 60 + 3) % 24;
            minutes = time (0) / 60 % 60;
            seconds = time (0) % 60;
            cout << hours << ":";
            if (minutes < 10){
                cout << "0";
            }
            cout << minutes << ":";
            if (seconds < 10){
                cout << "0";
            }
            cout << seconds << endl;
            last_time = time(0);
        }
    }
    return 0;
}

5. By OrHy3

C++ Clock by OrHy3 that displays the current time. ( Source )

#include <iostream>
using namespace std;
int main() {
    cout << __TIME__ << endl;
}

6. By aaditya sohani

Made by aaditya sohani the clock displays the current time of India. ( Source )

#include <iostream>
#include<ctime>
using namespace std;

int main() {
int hrs,min,sec,a,b;
sec =time(0)%60;
a=time(0)/60;
min=a%60+30;
b=a/60;
hrs=b%24+5;
if(min>60)
{
    hrs+=1;
    min -=60;
    
}
if(hrs>24)
{
    hrs -=24;
}
cout <<"time in format hrs:min:sec>>>"<<endl<<hrs<<":"<<min<<":"<<sec;
    return 0;
}

7. By Imagine Existance

Made by Imagine Existance. The clock displays the current time of Florida. ( Source )

#include <iostream>
#include <ctime>
#include <string>
using namespace std;
//FL time, to change turn x into something diffrent or take or add time from sec min or hou//

int main() {
	int x=4;
	//defines hour time diffrance in states//
	int t=time(0);
	//defines time//
	int sec;
	//creates sec group//
	int min;
	//creates min group//
	int hou;
	//creates hou group//
	string p;
	//creates p group//
	sec=t%60;
	//defines sec//
	min=(t/60)%60;
	//defines min//
	hou=((t/3600)%24)-x;
	//defines hou in florida timezone//
	p="am";
	//creates default group of p//
	if (hou<1){
		hou=((t/3600)%(24+x))-x;
	}
	//fixes negative issue//
	if (hou>12){
		p="pm";
	}
	//tests if it is bigger than 12 and changes
	//p//
	if (hou==0){
		hou=12;
	}
	//since it is mod 12 0 is 12, 13 would have 
	//12 and 0//
	cout<<"F.L. time"<<endl;
	//tells the time zone//
	cout<<hou%12<<":"<<min<<":"<<sec;
	//tells hours miniutes and seconds//
	cout<<endl<<"time period: "<<p;
	//tells time period//
	return 0;
}

8. By Djole HD

Made by Djole HD. It displays your current local time. ( Source )

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <unistd.h>

struct tm *tmp;
time_t a;

int main(){
    while(1){
    a = time(0);
    tmp = std::localtime(&a);
    std::cout << tmp->tm_hour << ":" << tmp->tm_min << ":" << tmp->tm_sec;
        break;

}
}

9. By Nikhil Samdariya

Made by Nikhil Samdariya. The clock displays the current time of the system in which its running on, like your computer. ( Source )

#include <iostream>
#include<ctime>
using namespace std;

int main() {
//current date /time based on current system 
time_t now = time (0) ;
// convert now to string form 
char*dt =ctime(&now);
cout <<"the local ''Greenwitch mean ''date &time is "<<dt<<endl;

    return 0;
}

10. By Viktor Shekhmatov

Made by Viktor Shekhmatov. You have to enter your time zone to get the current time. ( Source )

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main () {
    time(0);
    int h_value;
    int n = time(0);
cout << "Please enter you timezone value"<<endl;
cin >> h_value;
cout << "The format of your timezone: +"<<h_value << endl;
    cout << "     "<<"------------"<<endl;
    cout << "     | ";
    cout <<(n/3600+h_value)%24<< ":"<< n % 3600/600 << n/60%10<<":" << n % 60 / 10 << n % 10 << " |" << endl;
    cout << "     "<<"------------"<<endl;
    }

11. By fallout015

Made by fallout015. The clock displays the current day, year, date and time. ( Source )

#include <iostream>
#include <ctime>
using namespace std;

int main() {
	time_t current;
	time(&current);
	cout << ctime(&current) << endl;
	return 0;
}

12. By Rafid Hossain

C++ Clock by Rafid Hossain. It displays the date and time of your region. ( Source )

#include <iostream>
using namespace std;

int main(){
    cout<<"     __________________________"<<endl;
    cout<<"     |        C++ CLOCK       |\n     |        .________.      |\n     |  time: |"<<__TIME__<<"|      |\n     |        |________|      |"<<endl;
    cout<<"     |       .___________.    |"<<endl;
   cout<<"     | date: |"<<__DATE__<<"|    |"<<endl;
    cout<<"     |       |___________|    |\n     |________________________|";
}

13. By Junaid Ahmed

Made by Junaid Ahmed that displays the current date and time along with the number of seconds that has passed since 1 January 1970. ( Source )

#include <iostream>
#include <ctime>
using namespace std;
int main( )
{
// current date/time based on current system
time_t now = time(0);
cout << "Number of sec since January 1,1970:" << now << endl;
tm *ltm = localtime(&now);
// print various components of tm structure.
cout << "Year: "<< 1900 + ltm->tm_year << endl;
cout << "Month: "<< 1 + ltm->tm_mon<< endl;
cout << "Day: "<< ltm->tm_mday << endl;
cout << "Time: "<< 1 + ltm->tm_hour << ":";
cout << 1 + ltm->tm_min << ":";
cout << 1 + ltm->tm_sec << endl;
}

14. By phip

C++ Analog clock by phip that displays time with both the number and the clock hand. ( Source )

// created by Philipp Franke
// old fashioned analog watch
// inspired by Janes boredom Code


#include <iostream>
#include <ctime>
using namespace std;


int main() {
int zeit=time(0);
int h,m,md,hd;
int x=22;
int y=12;

// to change the style of the watch hands change the ascii-codes in the signs-attribute
char signs[2]={char(249),char(248)};

h=(zeit/3600)%24;
m=zeit/60%60;
hd=h%12;
if(m%5<3)md=m/5%12;
else md=(m+2)/5%12;
//hd=10;
//md=1;
//cout<<hd<<":"<<md<<endl;

int mpl[12]={0,-1,-3,0,3,1,0,-1,-3,0,3,1};

int add[12]={x/2,-(mpl[hd]*y/2-x/2),-(mpl[hd]*y/2-x/2),y/2,-mpl[hd]*y/2+x/2,x/2-y/2,x/2,-(mpl[hd]*y/2-x/2),-(mpl[hd]*y/2-x/2),y/2,-mpl[hd]*y/2+x/2,x/2-y/2};
int addm[12]={x/2, -(mpl[md]*y/2-x/2), -(mpl[md]*y/2-x/2), y/2, -mpl[md]*y/2+x/2, x/2-y/2,x/2, -(mpl[md]*y/2-x/2), -(mpl[md]*y/2-x/2), y/2, -mpl[md]*y/2+x/2, x/2-y/2};

for ( int i=1;i<y;i++){
	for (int j=1;j<x;j++){
		if (j==x/2&&i==y/2) cout<<char(249); // middle point
		
				else if (hd==0 && j==x/2 && i<=y/2 && i>2) cout<<signs[1];

		else if (hd==6 && j==x/2 && i>=y/2 && i<y-2) cout<<signs[1];

		else if (hd==3 && i==y/2 && j>=x/2 && j<x-4) cout<<signs[1];

		else if (hd==9 && i==y/2 && j<=x/2 && j>4) cout<<signs[1];
		
		else if ((hd<3||hd>9) && j==i*mpl[hd] + add[hd] && i<=y/2 && j<x-2 && j>2 && i>2 && i<y-2) cout<<signs[1];

		else if (hd>3&&hd<9 && j==i*mpl[hd] + add[hd] && i>=y/2 && j>2 && j<x-2 && i<y-2) cout<<signs[1];

		else if (md==0 && j==x/2 && i<=y/2) cout<<signs[0];

		else if (md==3 && i==y/2 && j>=x/2) cout<<signs[0];
		else if (md==9 && i==y/2 && j<=x/2) cout<<signs[0];

		else if (md==6 && j==x/2 && i>=y/2) cout<<signs[0];
		
		else if ((md<3||md>9) && j==i*mpl[md] + addm[md] && i<=y/2) cout<<signs[0];
		
		else if ((md>3&&md<9) && j==i*mpl[md]+addm[md] && i>=y/2) cout<<signs[0];
		
		else if (j==x/2 && (i==1||i==y-1)) cout<<"|"; //12 & 6 hour markers
		else if (i==y/2 && (j==1||j==x-1))cout<<"-"; //3 & 9 hour markers
		else cout<<" ";
	}
	cout<<endl;
}
cout<<endl;
cout<<"UTC ";
if (h<10) cout<<"0";
cout<<h<<":";
if (m<10)cout<<"0";
cout<<m<<endl;
	return 0;
}

15. By SomeOne

Made by SomeOne. This c++ clock only works on linux. ( Source )

8:40:20  AM
#include <iostream>
#include <ctime>
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <unistd.h>
using namespace std;
int main(){
	int hour;
	int minute;
	int second;
	int sec = 1000000;
	for(int x = 0; x < 12;){
	time_t now = time(0);
	tm* ltm = localtime(&now);
	hour = ltm->tm_hour;
	minute = ltm->tm_min;
    second = ltm->tm_sec;
	string tim;
	if(hour > 12){
		hour = hour - 12;
		tim = " PM";
	}else{
		tim = " AM";
	}
	
	cout << "" << hour << ":" << minute << ":" << second << " " << tim << endl;;
	usleep(sec);
	system("clear");
}
}

16. By Qualop team

Made by Qualop team. ( Source )

-----------------------------
Date     11/7/2022
-----------------------------
Time     11:41
-----------------------------
Day      1
-----------------------------
Have a nise day.
-----------------------------
#include<iostream>
#include<cmath>
#include <ctime>
using namespace std;

int main()
{

        time_t t = time(NULL);
 tm* timePtr = localtime(&t);

        cout << "-----------------------------" << endl;
        cout << "Date     " << (timePtr->tm_mday)<<"/"<< (timePtr->tm_mon)+1 <<"/"<< (timePtr->tm_year)+1900<< endl;
        cout << "-----------------------------" << endl;
        cout << "Time     " << (timePtr->tm_hour)+3 <<":"<< (timePtr->tm_min) << endl; 
        cout << "-----------------------------" << endl;
        cout << "Day      " << (timePtr->tm_wday) << endl;
        cout << "-----------------------------" << endl;
        cout << "Have a nise day." << endl;
        cout << "-----------------------------" << endl;

    return 0;
}

17. By Tretyakov Andrey

Made by Tretyakov Andrey. C++ digital clock. ( Source )

Mon Jul 11 08:42:31 2022

 ####   ####            #### 
#    # #    #   #    #      #
#    # #    # # #    #      #
        ####     ####   #### 
#    # #    # #      # #     
#    # #    #        # #     
 ####   ####            ####
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <time.h>

void horizontal(const uint8_t stripes[4], uint8_t *buf)
{
    const int offset[] = {1,8,17,24};
    int a,b;
    for(a=0;a<4;a++)
    if(!stripes[a])
    for(b=0;b<4;b++)
    buf[b+offset[a]] = ' ';
}

void vertical(const uint8_t stripes[8], uint8_t *buf)
{
    const int offset[] = {0,5,7,12,16,21,23,28};
    int a, b;
    for(a=0;a<8;a++)
    if(!stripes[a])
    {
        buf[offset[a]] = ' ';
        buf[30+offset[a]] = ' ';
    }
}

int main(void)
{
    const uint8_t layout[] = {0x77,0x24,0x5D,0x6D,0x2E,0x6B,0x7B,0x25,0x7F,0x6F};
    uint8_t *ptr, buffer[] = " ####   ####     ####   #### \n"
                             "#    # #    #   #    # #    #\n"
                             "#    # #    # # #    # #    #\n"
                             " ####   ####     ####   #### \n"
                             "#    # #    # # #    # #    #\n"
                             "#    # #    #   #    # #    #\n"
                             " ####   ####     ####   ####";
    time_t t;
    time(&t);
    ptr = (uint8_t *)strchr(ctime(&t),':');
    printf("%s\n",ctime(&t));
    uint8_t test[] = {layout[ptr[-2]-'0'],layout[ptr[-1]-'0'],layout[ptr[1]-'0'],layout[ptr[2]-'0']};
    uint8_t t1[] = {(uint8_t)(test[0]&1),(uint8_t)(test[1]&1),(uint8_t)(test[2]&1),(uint8_t)(test[3]&1)};
    uint8_t t2[] = {(uint8_t)((test[0]>>1)&1),(uint8_t)((test[0]>>2)&1),
    (uint8_t)((test[1]>>1)&1),(uint8_t)((test[1]>>2)&1),
    (uint8_t)((test[2]>>1)&1),(uint8_t)((test[2]>>2)&1),
    (uint8_t)((test[3]>>1)&1),(uint8_t)((test[3]>>2)&1)};
    uint8_t t3[] = {(uint8_t)((test[0]>>3)&1),(uint8_t)((test[1]>>3)&1),
    (uint8_t)((test[2]>>3)&1),(uint8_t)((test[3]>>3)&1)};
    uint8_t t4[] = {(uint8_t)((test[0]>>4)&1),(uint8_t)((test[0]>>5)&1),
    (uint8_t)((test[1]>>4)&1),(uint8_t)((test[1]>>5)&1),
    (uint8_t)((test[2]>>4)&1),(uint8_t)((test[2]>>5)&1),(uint8_t)((test[3]>>4)&1),
    (uint8_t)((test[3]>>5)&1)};
    uint8_t t5[] = {(uint8_t)((test[0]>>6)&1),(uint8_t)((test[1]>>6)&1),
    (uint8_t)((test[2]>>6)&1),(uint8_t)((test[3]>>6)&1)};
    horizontal(t1,buffer);
    vertical(t2,buffer+30);
    horizontal(t3,buffer+90);
    vertical(t4,buffer+120);
    horizontal(t5,buffer+180);
    puts((char *)buffer);
    return 0;
}