- Introduction
- Features
- Prerequisites
- Installation
- Usage
- Code Overview
- How It Works
- Customization
- Known Issues
- Contributing
- License
This project is a simple yet advanced digital clock written in the C programming language. The clock displays the current date and time in a user-friendly format, with features such as a 12-hour clock, AM/PM notation, a clean interface, and continuous updates every second. The program is designed to run in a terminal and is suitable for learning purposes, demonstration, or integration into larger projects.
- Real-time Date and Time Display: Continuously shows the current date and time in the format
DD-MM-YYYY | HH:MM:SS AM/PM
. - 12-Hour Format: Time is displayed in a 12-hour format with an AM/PM indicator.
- Clear and User-Friendly Interface: The clock clears the screen before each update, ensuring the display remains clean and easy to read.
- Welcome Message: The program includes a welcome message with instructions on how to exit.
- Cross-Platform Compatibility: The program is designed to work on UNIX-like systems (Linux, macOS) and can be adapted for Windows.
To compile and run this program, you need:
- A C compiler like
gcc
. - A terminal or command prompt to execute the program.
- A UNIX-like environment (for Windows users, consider using Cygwin or WSL for better compatibility).
First, clone this repository to your local machine using git
:
git clone https://github.com/mdriyadkhan585/advanced-digital-clock-C
Navigate to the directory containing the advanced_clock.c
file and compile the program using gcc
:
cd advanced-digital-clock-C
gcc -o advanced_clock advanced_clock.c
Once compiled, you can run the program using:
./advanced_clock
When you run the program, it will display the current date and time in a formatted manner. The clock will update every second.
To exit the program, press Ctrl+C
in the terminal.
======================================
Welcome to the Digital Clock
======================================
Press Ctrl+C to exit the program.
Current Date and Time:
======================================
Date: 01-09-2024
Time: 02:23:15 PM
======================================
-
clearScreen()
: Clears the terminal screen before each update. This ensures that the clock appears in the same position on the screen, creating a clean display. -
printWelcomeMessage()
: Displays a welcome message and instructions for exiting the program. This is shown at the top of the clock interface. -
displayClock()
: The core function that retrieves the current date and time, formats it, and prints it to the screen. It also handles the 12-hour format and AM/PM conversion. -
main()
: The entry point of the program, which callsdisplayClock()
to start the clock.
The program works by continuously fetching the current system time using the time()
function from the time.h
library. It then converts this time to a human-readable format, considering the user's local timezone. The program then formats the time in a 12-hour clock with an AM/PM indicator. The screen is cleared before each update to maintain a clean display, and the time is printed to the terminal every second.
You can customize the clock by modifying the following:
- Date and Time Format: Change the formatting in the
printf
statements withindisplayClock()
to alter how the date and time are displayed. - Colors: You can add ANSI escape codes to change the text color for the clock, making it more visually appealing.
- Additional Features: Consider adding new features like an alarm, a stopwatch, or different time zones.
- Screen Clearing: The
clearScreen()
function uses ANSI escape codes, which are supported on most UNIX-like systems but may not work in all environments, particularly on Windows without special configuration. - Time Drift: Over long periods, slight inaccuracies may accumulate due to the way
sleep(1)
operates. This should not be noticeable for general use but may become apparent if the program runs for extended periods.
Contributions are welcome! If you have suggestions, improvements, or bug fixes, feel free to submit a pull request or open an issue in the repository.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes and commit them (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.