Repository navigation
Expand file tree
/
Copy pathMisc.cpp
More file actions
66 lines (57 loc) · 1.58 KB
/
Copy pathMisc.cpp
File metadata and controls
66 lines (57 loc) · 1.58 KB
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
#include "Misc.h"
vector<string> Split(const string& str, char splitter)
{
vector<string> res;
size_t pos = 0, spos = str.find(splitter);
while (spos != string::npos)
{
res.push_back(str.substr(pos, spos - pos));
pos = spos + 1;
spos = str.find(splitter, pos);
}
res.push_back(str.substr(pos, str.length() - pos));
return res;
}
string DateToString(SYSTEMTIME& date)
{
return to_string(date.wYear)
+ '-' + to_string(date.wMonth)
+ '-' + to_string(date.wDayOfWeek)
+ '-' + to_string(date.wDay)
+ '-' + to_string(date.wHour)
+ '-' + to_string(date.wMinute)
+ '-' + to_string(date.wSecond)
+ '-' + to_string(date.wMilliseconds);
}
SYSTEMTIME StringToDate(string str)
{
SYSTEMTIME time{};
vector<string> splitter = Split(str, '-');
if (splitter.size() == 8)
{
time.wYear = atoi(splitter[0].c_str());
time.wMonth = atoi(splitter[1].c_str());
time.wDayOfWeek = atoi(splitter[2].c_str());
time.wDay = atoi(splitter[3].c_str());
time.wHour = atoi(splitter[4].c_str());
time.wMinute = atoi(splitter[5].c_str());
time.wSecond = atoi(splitter[6].c_str());
time.wMilliseconds = atoi(splitter[7].c_str());
}
return time;
}
string GetMessageDate(SYSTEMTIME& date)
{
char buffer[30];
sprintf_s(buffer, "%02d/%d/%d %02d:%02d:%02d", date.wDay, date.wMonth, date.wYear, date.wHour, date.wMinute, date.wSecond);
return buffer;
}
unsigned long long DateToULL(SYSTEMTIME& date)
{
return date.wSecond
+ (date.wMinute * 60)
+ (date.wHour * 60 * 60)
+ (date.wDay * 60 * 60 * 24)
+ (date.wMonth * 60 * 60 * 24 * 30)
+ ((double)date.wYear * 60 * 60 * 24 * 30 * 365.25);
}