Skip to content

Instantly share code, notes, and snippets.

@blippy
Created June 11, 2016 10:08
Show Gist options
  • Select an option

  • Save blippy/c3e57066bdb1717fb7baaa6e8ab95a6c to your computer and use it in GitHub Desktop.

Select an option

Save blippy/c3e57066bdb1717fb7baaa6e8ab95a6c to your computer and use it in GitHub Desktop.
Format date and time
#include <ctime>
void printtime()
{
std::time_t t = std::time(nullptr);
char buffer[80];
strftime(buffer, 80, "%Y-%m-%d", std::localtime(&t));
std::cout << "*" << buffer << "*\n" ; // *2016-06-11*
strftime(buffer, 80, "%H:%M:%S", std::localtime(&t));
std::cout << "*" << buffer << "*\n" ; // *11:05:08*
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment