Skip to content

Commit 1f9b222

Browse files
Create time_unix.cpp
1 parent 963dd9a commit 1f9b222

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

time_unix.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <iostream>
2+
#include <chrono>
3+
4+
unsigned long long getUnixTime(std::chrono::system_clock::time_point p0 =
5+
std::chrono::system_clock::time_point{
6+
std::chrono::seconds{ 0 } }) {
7+
if(p0 ==
8+
std::chrono::system_clock::time_point{ std::chrono::seconds{ 0 } }) {
9+
p0 = std::chrono::system_clock::now();
10+
}
11+
return std::chrono::duration_cast<std::chrono::seconds>(
12+
p0.time_since_epoch())
13+
.count();
14+
}
15+
16+
int main() {
17+
std::cout << getUnixTime() << std::endl; // 1689911880
18+
return 0;
19+
}

0 commit comments

Comments
 (0)