c print system time stamp

Solutions on MaxInterview for c print system time stamp by the best coders in the world

showing results for - "c print system time stamp"
Filippo
12 Aug 2016
1#include <time.h>
2#include <stdlib.h>
3#include <stdio.h>
4
5int main(void)
6{
7    time_t current_time;
8    char* c_time_string;
9
10    /* Obtain current time. */
11    current_time = time(NULL);
12
13    if (current_time == ((time_t)-1))
14    {
15        (void) fprintf(stderr, "Failure to obtain the current time.\n");
16        exit(EXIT_FAILURE);
17    }
18
19    /* Convert to local time format. */
20    c_time_string = ctime(¤t_time);
21
22    if (c_time_string == NULL)
23    {
24        (void) fprintf(stderr, "Failure to convert the current time.\n");
25        exit(EXIT_FAILURE);
26    }
27
28    /* Print to stdout. ctime() has already added a terminating newline character. */
29    (void) printf("Current time is %s", c_time_string);
30    exit(EXIT_SUCCESS);
31}
32