Skip to content
Search

Date

lastmod 2025-01-19created 2016-01-196 edits

Format

  • %N nanoseconds (000000000..999999999)
  • %s seconds since 1970-01-01 00:00:00 UTC

Current time

will return the number of seconds since the epoch.

$ date +%s

returns the seconds and current nanoseconds.

$ date +%s%N

will give you the number of milliseconds since the epoch - current seconds plus the left three of the nanoseconds.

$ date +%s%N | cut -b1-13

To print the current time in milliseconds:

$ date +%s%3N

Calculating a date some days ago

Use the -d option.

date -d "-1 day" +%Y%m%d

Used in Answer:SteelScrap#Automatic compression bash script for cron.

See also

Favorite site

author Zer0 sitemap