Skip to content

Instantly share code, notes, and snippets.

@firatsarlar
Created July 13, 2018 20:15
Show Gist options
  • Save firatsarlar/b447c4052a17d372f6478d9643d1d180 to your computer and use it in GitHub Desktop.
Save firatsarlar/b447c4052a17d372f6478d9643d1d180 to your computer and use it in GitHub Desktop.
#include <string>
#include <iomanip>
#include <sstream>
#include <ctime>
void tmstamp() {
std::stringstream stream;
time_t rawtime;
tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
stream << (timeinfo->tm_year) + 1900 << "/"
<< std::setfill('0') << std::setw(2) << setiosflags(ios_base::right) << timeinfo->tm_mon +1
<< "/" << timeinfo->tm_mday << " "
<< timeinfo->tm_hour
<< ":" << timeinfo->tm_min
<< ":" << timeinfo->tm_sec;
// The str() function of output stringstreams return a std::string.
cout << stream.str() << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment