blob: 5370e5f2a9dc073ecec470f50f8e2280d58c0b51 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include <stdio.h>
#include <time.h>
int main(int argc, const char *argv[])
{
long int seconds_since_epoch;
struct tm current_time, *time_ptr;
int hour, minute, second, day, month, year;
seconds_since_epoch = time(0);
printf("time() - seconds since epoch: %ld\n", seconds_since_epoch);
time_ptr = ¤t_time;
localtime_r(&seconds_since_epoch, time_ptr);
hour = current_time.tm_hour;
minute = time_ptr->tm_min;
second = *((int *) time_ptr);
printf("Current time is: %02d:%02d:%02d\n", hour, minute, second);
return 0;
}
|