Created
October 28, 2019 02:00
-
-
Save moon03432/2b9937a153e6cb546ab0b458027fdb97 to your computer and use it in GitHub Desktop.
get current time (C++)
This file contains hidden or 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 <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