-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathahr.c
More file actions
29 lines (24 loc) · 784 Bytes
/
ahr.c
File metadata and controls
29 lines (24 loc) · 784 Bytes
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
#include <stdio.h>
#include <time.h>
// Function to generate the auto-generated timestamp in the format "counter:timestamp"
void ahr() {
struct timespec currentTime;
clock_gettime(CLOCK_REALTIME, ¤tTime);
// Extract individual components of the timestamp
struct tm timeInfo;
localtime_r(¤tTime.tv_sec, &timeInfo);
// Format and print the auto-generated timestamp
printf("%04d%02d%02d%02d%02d%02d.%09ld\n",
timeInfo.tm_year + 1900,
timeInfo.tm_mon + 1,
timeInfo.tm_mday,
timeInfo.tm_hour,
timeInfo.tm_min,
timeInfo.tm_sec,
currentTime.tv_nsec);
}
int main() {
// Call the function to generate and print the auto-generated timestamp
ahr();
return 0;
}