Skip to content

Commit ba67e4a

Browse files
timestamp.cpp
1 parent be11bb0 commit ba67e4a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

timestamp.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
std::string get_timestamp() {
5+
time_t now = time(NULL);
6+
struct tm* ltm = localtime(&now);
7+
char buffer[80];
8+
9+
strftime(buffer, 80, "%Y-%m-%d-%H-%M-%S", ltm);
10+
11+
return std::string(buffer);
12+
}
13+
14+
int main() {
15+
std::cout << "current timestamp: " << get_timestamp() << std::endl;
16+
//current timestamp: 2021-08-30-01-53-30
17+
return 0;
18+
}

0 commit comments

Comments
 (0)