AWK - Time Functions

AWK has the following built-in time functions −
This function returns the current time of the day as the number of seconds since the Epoch (1970-01-01 00:00:00 UTC on POSIX systems).
[jerry]$ awk 'BEGIN {
   print "Number of seconds since the Epoch = " systime()
}'
On executing this code, you get the following result −
Number of seconds since the Epoch = 1418574432

This function converts datespec string into a timestamp of the same form as returned by systime(). The datespec is a string of the form YYYY MM DD HH MM SS.
[jerry]$ awk 'BEGIN {
   print "Number of seconds since the Epoch = " mktime("2014 12 14 30 20 10")
}'
On executing this code, you get the following result −
Number of seconds since the Epoch = 1418604610

This function formats timestamps according to the specification in format.
[jerry]$ awk 'BEGIN {
   print strftime("Time = %m/%d/%Y %H:%M:%S", systime())
}'
On executing this code, you get the following result −
Time = 12/14/2014 22:08:42

The following time formats are supported by AWK −
%a
The locale’s abbreviated weekday name.
%A
The locale’s full weekday name.
%b
The locale’s abbreviated month name.
%B
The locale’s full month name.
%c
The locale’s appropriate date and time representation. (This is %A %B %d %T %Y in the C locale.)
%C
The century part of the current year. This is the year divided by 100 and truncated to the next lower integer.
%d
The day of the month as a decimal number (01–31).
%D
Equivalent to specifying %m/%d/%y.
%e
The day of the month, padded with a space if it is only one digit.
%F
Equivalent to specifying %Y-%m-%d. This is the ISO 8601 date format.
%g
The year modulo 100 of the ISO 8601 week number, as a decimal number (00–99). For example, January 1, 1993 is in week 53 of 1992. Thus, the year of its ISO 8601 week number is 1992, even though its year is 1993. Similarly, December 31, 1973 is in week 1 of 1974. Thus, the year of its ISO week number is 1974, even though its year is 1973.
%G
The full year of the ISO week number, as a decimal number.
%h
Equivalent to %b.
%H
The hour (24-hour clock) as a decimal number (00–23).
%I
The hour (12-hour clock) as a decimal number (01–12).
%j
The day of the year as a decimal number (001–366).
%m
The month as a decimal number (01–12).
%M
The minute as a decimal number (00–59).
%n
A newline character (ASCII LF).
%p
The locale’s equivalent of the AM/PM designations associated with a 12-hour clock.
%r
The locale’s 12-hour clock time. (This is %I:%M:%S %p in the C locale.)
%R
Equivalent to specifying %H:%M.
%S
The second as a decimal number (00–60).
%t
A TAB character.
%T
Equivalent to specifying %H:%M:%S.
%u
The weekday as a decimal number (1–7). Monday is day one.
%U
The week number of the year (the first Sunday as the first day of week one) as a decimal number (00–53).
%V
The week number of the year (the first Monday as the first day of week one) as a decimal number (01–53).
%w
The weekday as a decimal number (0–6). Sunday is day zero.
%W
The week number of the year (the first Monday as the first day of week one) as a decimal number (00–53).
%x
The locale’s appropriate date representation. (This is %A %B %d %Y in the C locale.).
%X
The locale’s appropriate time representation. (This is %T in the C locale.).
%y
The year modulo 100 as a decimal number (00–99).
%Y
The full year as a decimal number (e.g. 2011).
%z
The time-zone offset in a +HHMM format (e.g., the format necessary to produce RFC 822/RFC 1036 date headers).
%Z
The time zone name or abbreviation; no characters if no time zone is determinable.
 Print
 Add Notes
 Bookmark this page