Skip to content

Instantly share code, notes, and snippets.

@moon03432
Created October 28, 2019 02:00
Show Gist options
  • Save moon03432/2b9937a153e6cb546ab0b458027fdb97 to your computer and use it in GitHub Desktop.
Save moon03432/2b9937a153e6cb546ab0b458027fdb97 to your computer and use it in GitHub Desktop.
get current time (C++)
#include <iostream>
#include <chrono>
#include <ctime>
using namespace std;
int main() {
chrono::time_point<chrono::system_clock> timePoint = chrono::system_clock::now();
time_t now = chrono::system_clock::to_time_t(timePoint);
cout << ctime(&now) << endl;
struct tm *timeinfo = localtime(&now);
char buffer[80];
strftime(buffer,sizeof(buffer),"%F.%T.%z",timeinfo);
std::string str(buffer);
cout << str << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment