-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime_show.h
35 lines (27 loc) · 835 Bytes
/
time_show.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once
#include <chrono> // chrono::system_clock
#include <ctime> // localtime
#include <sstream> // stringstream
#include <iomanip> // put_time
#include <string> // string
std::string return_current_time_and_date()
{
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");
ss << std::put_time(std::localtime(&in_time_t), "%d-%m-%Y %X");
return ss.str();
}
std::string show_current_time()
{
time_t rawtime;
struct tm* timeinfo;
char buffer[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, sizeof(buffer), "%d-%m-%Y %H:%M:%S", timeinfo);
std::string str(buffer);
//std::cout << str;
return str;
}