First Method
Printing current date and time using time()
Second Method
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
time_t my_time = time (NULL);
printf ( "%s" , ctime (&my_time));
return 0;
}
|
Output:
It will show the current day, date and localtime,
in the format Day Month Date hh:mm:ss Year
Third Method
Here we have used chrono library to print current date and time . The chrono library is a flexible collection of types that tracks time with varying degrees of precision .
The chrono library defines three main types as well as utility functions and common typedefs.
-> clocks
-> time points
-> durations
Code to print current date, day and time .
#include <chrono>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
auto timenow =
chrono::system_clock::to_time_t(chrono::system_clock::now());
cout << ctime (&timenow) << endl;
}
|
Output:
It will show the current day, date and localtime,
in the format Day Month Date hh:mm:ss Year
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
10 Dec, 2018
Like Article
Save Article