awk strftime time zone dependency on TZ environment variable
0 reputation · 28 Mar 2021, 10:24 UTC
strftime() function formats epoch seconds into date strings based on the TZ environment variable. While mktime() generates a timestamp from date components, the resulting output shifts automatically according to the system's local time zone unless explicitly overridden.
This behavior creates challenges when scripts must maintain consistent UTC output across different environments without modifying the global shell state. Since awk does not provide a parameter to specify a time zone directly within the strftime call, the logic relies entirely on the environment state at the time of process execution.
Is there a reliable method to force strftime to output UTC strings without setting the TZ variable for the entire shell? Additionally, how does mktime behave if the TZ variable is changed mid-execution within a long-running awk process?