Skip to content

Instantly share code, notes, and snippets.

@edjeordjian
Last active March 20, 2020 21:13
Show Gist options
  • Save edjeordjian/17fd177a0146377965324fda5b7a9d5c to your computer and use it in GitHub Desktop.
Save edjeordjian/17fd177a0146377965324fda5b7a9d5c to your computer and use it in GitHub Desktop.
A simple way to create a customized timestamp in C++.
#include <ctime>
#include <bits/stdc++.h>
std::string getTimestamp(char* format) {
std::time_t epoch_time = std::time(nullptr);
std::stringstream stream;
stream << std::put_time( std::localtime(&epoch_time), format );
return stream.str();
}
int main(int argc, char *argv[]){
std::cout << getTimestamp( (char*) "Current timestamp is: %Y-%m-%d %H:%M:%S" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment