BLog

ImprintImpressum
PrivacyDatenschutz
DisclaimerHaftung
Downloads 

Date/Time conversions on the command line

Frequently, but not frequent enough for simply remembering the commands, we need to convert a Unix time stamp to a date/time string and/or vice versa. Here are the relevant commands using the date(1) command line utility on FreeBSD or macOS.

The actual date/time, printed into a kind of the ISO format:
  date "+%Y-%m-%d %H:%M:%S"

The actual date/time, output as a Unix time  stamp:
  date "+%s"

Conversion of a Unix time stamp into a kind of the ISO format:
  date -jf "%s" "+%Y-%m-%d %H:%M:%S" 1519640774

Conversion of a date/time string to the Unix time stamp:
  date -jf "%Y-%m-%d %H:%M:%S" "+%s" "2018-02-26 07:26:14"

In all commands, use the -u flag for working with the UTC zone.

Copyright © Dr. Rolf Jansen - 2018-06-12 03:32:28

PROMOTION