Site icon LinuxCommands.site

Awk time functions: systime, mktime, strftime

Today, I would like to share with you how to use the awk time function:

Syntax

awk 'pattern {  action }'

Example

In the following example, we use the awk systime function to get the current timestamp.

awk 'BEGIN{nowTimestamp=systime();print nowTimestamp;}'

In the following example, we use the awk mktime function to create a timestamp at the specified time.

awk 'BEGIN{print "Number of seconds since the Epoch = " mktime("2022 10 08 20 20 10")}'

In the following example, we use the awk strftime function to output the timestamp formatted time string.

awk 'BEGIN {print strftime("Time = %m/%d/%Y %H:%M:%S", 1665140876)}'

Exit mobile version