codegurukool.com · Free coding tutorials & online compiler

Home › C++ Tutorial › C++ date and time

C++ date and time

ctime basics.

time(0) gives seconds since 1970. ctime converts it to readable text.

Example code

#include <iostream>
#include <ctime>
using namespace std;
int main() {
  time_t now = time(0);
  cout << ctime(&now);
  return 0;
}

Run this code in the online editor

← C++ filesC++ errors and debugging →