The -d option format of the Bash command date

In date's man page:

-d, --date=STRING         display time described by STRING, not 'now'

Sounds like you should input a exact date, but I find date -d "-1 day" works.

I just want a list of the format of -d option of the command date. I googled, but find none.

Answers


From man date:

DATE STRING

The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.

Then you can get more info and examples typing

info date

Which you can find in Date input formats.

A date is a string, possibly empty, containing many items separated by whitespace. The whitespace may be omitted when no ambiguity arises. The empty string means the beginning of today (i.e., midnight). Order of the items is immaterial. A date string may contain many flavors of items:

  • calendar date items
  • time of day items
  • time zone items
  • combined date and time of day items
  • day of the week items
  • relative items
  • pure numbers.

I will try to list just a collection of what you can use with date -d:

  • (last|next) (second|minute|hour|day|month|year)
  • X (seconds|minutes|hours|days|months|years) ago, where X=...,-1,0,1,2,3,...
  • X (second|minute|hour|day|month|year) , where X=...,-1,0,1,2,3,...
  • yesterday, tomorrow
  • @XXXXXXXXX, where XXXXXXXX seconds since epoch

You can access its docs by

man date

You can even do this:

date -d yesterday

Need Your Help

Android Leanback library HorizontalGridView scrollToPosition doesn't work

android android-layout android-recyclerview android-tv leanback

I'm implementing an Android TV app and I'm using HorizontalGridView from the Leanback library. I have a custom layout.

pattern for matching a string

java regex pattern-matching

I'm trying to create a java.util.regex.Pattern that would match strings similar to the following: