In order to facilitate finding the current local day, date and time, C++ has defined several functions in the header file , so functions which will help us in achieving our objective of finding local day, date and time are:
- It is used to find the current calendar time.
- Its return type is time_t, which is an arithmetic data type capable of storing time returned by this function.
- If its argument is not NULL, then it assigns its argument the same value as its return value.
- It uses the argument of time(), which has the same value as the return value of time(), to fill a structure having date and time as its components, with corresponding time in local timezone.
- It is used to convert the contents in the structure filled by localtime into a human-readable version which finally returns day, date and time in the given format:
Day Month Date hh:mm:ss Year
It will show the current day, date and localtime, in the format Day Month Date hh:mm:ss Year
Points to remember:
- This program will give output different for different time zones as per the time in that time zone.
- The Day, Date and Time in the output is independent of the system day, date and time. You can change your system date and time settings, but still the output will not be affected, and will give the correct information.
This article is contributed by Mrigendra Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Java | Current date and time
- C program to print digital clock with current time
- Python program to find day of the week for a given date
- How to get Day, Month and Year from Date in Java
- Find day of the week for a given date
- Zeller's Congruence | Find the Day for a Date
- Date after adding given number of days to the given date
- Time difference between expected time and given time
- Print day of week using Gregorian Calendar in java
- Time Functions in Python | Set-2 (Date Manipulations)
- Convert timestamp to readable date/time in PHP
- Program to find the time after K minutes from given time
- Find the number of times every day occurs in a month
- Tomohiko Sakamoto's Algorithm- Finding the day of the week
- Learn C++ Programming Step by Step - A 20 Day Curriculum!
- Program to check if a date is valid or not
- Program to Convert Milliseconds to a Date Format in Java
- Changing One Clock Time to Other Time in Minimum Number of Operations
- Print system time in C++ (3 different ways)
- PHP | Converting string to Date and DateTime