Skip to content

Commit c17b87b

Browse files
committed
изменен алгоритм получения unix времени компьютера, теперь это действительно UTC/GMT
1 parent 013528e commit c17b87b

File tree

8 files changed

+18
-35
lines changed

8 files changed

+18
-35
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.depend
2+
*.layout
3+
*.o
4+
*.exe
-48 KB
Binary file not shown.

example/converter/converter.depend

Lines changed: 0 additions & 14 deletions
This file was deleted.

example/converter/converter.layout

Lines changed: 0 additions & 20 deletions
This file was deleted.

example/converter/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,14 @@ int main() {
2525
std::cout << "cet: " << iExampleTime2.getStr() << std::endl;
2626
xtime::cTime iExampleTime3(xtime::convertCetToGmt(iExampleTime2.getUnixTime()));
2727
std::cout << "gmt: " << iExampleTime3.getStr() << std::endl;
28+
29+
unsigned long long lastGmt = xtime::getUnixTime();
30+
while(1) {
31+
unsigned long long unix = xtime::getUnixTime();
32+
if(unix != lastGmt) {
33+
std::cout << "pc gmt: " << unix << "\r";
34+
lastGmt = unix;
35+
}
36+
}
2837
return 0;
2938
}
Binary file not shown.
-12.5 KB
Binary file not shown.

src/xtime.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ namespace xtime {
3232
unsigned long long getUnixTime() {
3333
time_t rawtime;
3434
time(&rawtime);
35-
return (unsigned long long)rawtime;
35+
struct tm* ptm;
36+
37+
ptm = gmtime(&rawtime);
38+
DateTime iTime(ptm->tm_mday, ptm->tm_mon + 1, ptm->tm_year + 1900, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
39+
return iTime.getUnixTime();
3640
}
3741

3842
unsigned long long getUnixTime(int day, int month, int year, int hour, int minutes, int seconds) {

0 commit comments

Comments
 (0)