linux bash - Parse date in custom format

后端 未结 4 898
挽巷
挽巷 2020-12-07 01:19

I have a date in a the %c format (could be any other) and I need to use it in the date command. %c is NOT the American format. It is the G

4条回答
  •  遥遥无期
    2020-12-07 01:53

    If you meant the formatting is wrong, I think what you want is:

    NOW=$(date +%c)
    date --date="$NOW" +%d/%m/%Y
    

    note the lowercase %d and %m.

    Locally, this is what I get:

    root@server2:~# NOW=$(date +%c)
    root@server2:~# date --date="$NOW" +%d/%m/%Y
    19/12/2013
    

提交回复
热议问题