Date conversion oneliners in bash

Some handy date conversion oneliners in bash.

  • Assuming we have a unix timestamp format (seconds since 1970-01-01 00:00:00 UTC) and we want to make it human readable:
  • Same as above, but we’d rather make the date output in a different format:
  • Need the above for a different timezone? Try this:
  • Date “now” in Tokyo, our custom output format:
  • 12 hours later from now in Tokyo:

For a list of possible timezones on your system, see ls /usr/share/zoneinfo.

  • date 30 days ago (useful i.e. to expire objects in the database):
  • First day of this month:
  • Last day 2 months ago:
  • Convert syslog date to unix timestamp – assuming your log line begins with:

you can convert it to unix timestamp with:

  • 2 days before/after 2018-08-01 - useful for increments in scripts:

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Lxadm.com.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.