Pages

C++ Date Time

The C++ language standard library does not provide a managed date type. C++ language  use c language structs and functions for date and time.For using date time manipulation include <ctime> header file will be include C++ programming code. There are following related in date time like  clock_t, time_t, size_t, and tm. 

Example for get current time

#include<iostream>
#include<ctime> // date time library
using namespace std;
int main()
{
    time_t get_time; //defined parameter for time()
    struct tm * ti; // variable for  store return ocaltime()
    time (&get_time);    // get time()
    ti = localtime(&get_time);// Using localtime()
    cout << "Current Date and Time in C++ = "<< asctime(ti);
  return 0;

}

Output:





asctime():

It is used to convert local-time into a human-readable version with format


Day Month Date hh:mm:ss Year

localtime()

It will be return value of time() with corresponding time in local timezone.