Created
August 9, 2020 09:46
-
-
Save igricart/efcfb3b402bf91a7b165df8b7a94ca7b to your computer and use it in GitHub Desktop.
Write time to a .txt file
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 <iomanip> | |
#include <chrono> | |
#include <ctime> | |
#include <iostream> | |
#include <string> | |
#include <fstream> | |
int main () | |
{ | |
auto now = std::chrono::system_clock::now(); | |
auto in_time_t = std::chrono::system_clock::to_time_t(now); | |
std::stringstream ss; | |
ss << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d %X"); | |
std::cout << ss.str() << std::endl; | |
std::ofstream file; | |
file.open("your_example.txt"); | |
file << ss.str() << std::endl; | |
file.close(); | |
return 0; | |
} | |
// in bash | |
// date "+%Y-%m-%d %H:%M:%S" > TIME.TXT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment