Advanced Programming in The UNIX Environment
Advanced Programming in The UNIX Environment
Jan Schaumann
[email protected]
https://stevens.netmeister.org/631/
time(3)
#include <time.h>
The time() function returns the value of time in seconds since 0 hours, 0 minutes, 0
seconds, January 1, 1970, Coordinated Universal Time.
(We already talked about the Y2K38 problem - see Week 01, Segment 3.)
2
Jan Schaumann 2022-10-06
gettimeofday(2)
#include <sys/time.h>
The system's notion of the current UTC time is obtained with the gettimeofday() call. The time
is expressed in seconds and microseconds since midnight (0 hour), January 1, 1970.
struct timeval {
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* and microseconds */
};
struct timezone {
int tz_minuteswest; /* of Greenwich */
int tz_dsttime; /* type of dst correction to apply */
}; 5
Jan Schaumann 2022-10-06
clock_gettime(2)
#include <sys/time.h>
The clock_gettime() function stores the time of the clock identified by clock_id into the
location specified by tp; clock_id CLOCK_REALTIME represents the amount of time
(in seconds and nanoseconds) since 00:00 Universal Coordinated Time, January 1,
1970.
7
Jan Schaumann 2022-10-06
#include <time.h>
The gmtime() function converts to Coordinated Universal Time (UTC) and returns a
pointer to the tm structure described in tm(3).
9
Jan Schaumann 2022-10-06
10
Jan Schaumann 2022-10-06
11
Jan Schaumann 2022-10-06
CS631 - Advanced Programming in the UNIX Environment
struct tm {
int tm_sec; /* seconds after the minute [0-61] */
...
}
struct tm {
int tm_sec; /* Seconds. [0-60] (1 leap second) */
...
}
12
Jan Schaumann 2022-10-06
#include <time.h>
The gmtime() function converts to Coordinated Universal Time (UTC) and returns a
pointer to the tm structure described in tm(3).
13
Jan Schaumann 2022-10-06
#include <time.h>
14
Jan Schaumann 2022-10-06
16
Jan Schaumann 2022-10-06
17
Jan Schaumann 2022-10-06
#include <time.h>
18
Jan Schaumann 2022-10-06
#include <time.h>
25
Jan Schaumann 2022-10-06
#include <time.h>
27
Jan Schaumann 2022-10-06
ff
• https://en.wikipedia.org/wiki/ISO_8601
• https://in niteundo.com/post/25326999628/falsehoods-programmers-believe-about-
time
• https://en.wikipedia.org/wiki/Coordinated_Universal_Time
• https://en.wikipedia.org/wiki/Leap_second
• http://hpiers.obspm.fr/eop-pc/products/bulletins/subscription.html
• https://pubs.opengroup.org/onlinepubs/9699919799/xrat/
V4_xbd_chap04.html#tag_21_04_16
• http://www.madore.org/~david/computers/unix-leap-seconds.html
30
Jan Schaumann 2022-10-06
fi