How can I change the format of a date from the command line?

后端 未结 6 1561
梦毁少年i
梦毁少年i 2020-12-19 17:04

What\'s the quickest way to convert a date in one format, say

2008-06-01

to a date in another format, say

6条回答
  •  醉话见心
    2020-12-19 17:29

    $ date -d '2005-06-30' +'%a %F'
    Thu 2005-06-30
    

    See man date for other format options.

    This option is available on Linux, but not on Darwin. In Darwin, you can use the following syntax instead:

    date -j -f "%Y-%m-%d" 2006-06-30 +"%a %F"
    

    The -f argument specifies the input format and the + argument specifies the output format.

    As pointed out by another poster below, you would be wise to use %u (numeric day of week) rather than %a to avoid localization issues.

提交回复
热议问题