Rick Cogley's Tech Logr

Short Technical Laser Bursts %%

RC Logr 20190131 193007

Thursday, 31 Jan, 2019

Sometimes you need a timestamp in a shell script, for example if you need to calculate the hmac signature for a payload you received from a web service. In Linux or Mac, you can do date -u +"%s" or date -u +"%s.%N" if you need the nanoseconds. Use Gnu gdate from brew on Mac because its stock date does not support %N. The -u tells it to return UTC, which you can leave off for local time. If you need to force a timezone, use something like TZ=":Japan" date +"%s". The result looks like 1548931141 or 1548931220.112871000.

RC Logr 20190131 193007 - Sometimes you need a timestamp … Rick Cogley
Back to Home Tweet Link