-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.cpp
87 lines (55 loc) · 1.6 KB
/
clock.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "clock.h"
Clock::Clock(QObject *parent) :
QObject(parent)
{
}
QString Clock::getTime()
{
std::time_t t = std::time(nullptr);
std::tm tm = *std::localtime(&t);
std::ostringstream oss;
oss << std::put_time(&tm, "%D %T");
return QString::fromStdString(oss.str());
};
void Clock::getTimeDateSplitted(QString& Year, QString& Month, QString& Day, QString& DoW, QString& Hour, QString& Min, QString& Sec)
{
std::time_t t = std::time(nullptr);
std::tm tm = *std::localtime(&t);
std::ostringstream oss;
oss << std::put_time(&tm, "%y");
Year= QString::fromStdString(oss.str());
oss.str("");
oss.clear();
oss << std::put_time(&tm, "%m");
Month= QString::fromStdString(oss.str());
oss.str("");
oss.clear();
oss << std::put_time(&tm, "%d");
Day= QString::fromStdString(oss.str());
oss.str("");
oss.clear();
oss << std::put_time(&tm, "%w");
DoW= QString::fromStdString(oss.str());
oss.str("");
oss.clear();
oss << std::put_time(&tm, "%H");
Hour= QString::fromStdString(oss.str());
oss.str("");
oss.clear();
oss << std::put_time(&tm, "%M");
Min= QString::fromStdString(oss.str());
oss.str("");
oss.clear();
oss << std::put_time(&tm, "%S");
Sec= QString::fromStdString(oss.str());
oss.str("");
oss.clear();
};
QString Clock::getDateReformated()
{
std::time_t t = std::time(nullptr);
std::tm tm = *std::localtime(&t);
std::ostringstream oss;
oss << std::put_time(&tm, "%m%d%y_%H%M%S");
return QString::fromStdString(oss.str());
};