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

后端 未结 6 1562
梦毁少年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:43

    If you're just looking to get the day of the week, don't try to match strings. That breaks when the locale changes. The %u format give you the day number:

     $ date -j -f "%Y-%m-%d" "2008-01-03" +"%u"
     4
    

    And indeed, that was a Thursday. You might use that number to index into an array you have in your program, or just use the number itself.

    See the date and strftime man pages for more details. The date manpage on OS X is the wrong one, though, since it doesn't list these options that work.

提交回复
热议问题