Last active
March 20, 2020 21:13
-
-
Save edjeordjian/17fd177a0146377965324fda5b7a9d5c to your computer and use it in GitHub Desktop.
A simple way to create a customized timestamp in C++.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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