Linux: date cmd doesn’t accept its own output string as input string

dateinputlinux

$ date
Mi 14. Jun 09:54:58 CEST 2017

$ date -d "Mi 14. Jun 09:54:58 CEST 2017" +%s
date: invalid date ‘Mi 14. Jun 09:54:58 CEST 2017’

Why wouldn't the date command accept its own output string as valid input string?

Best Answer

info date told me that -d option requires input in locale independent format. To get the output in such a format, use:

LC_TIME=C date

So the following should work:

date -d "$(LC_TIME=C date)" +%s

It's only a cumbersome example that has a little sense (compare date +%s) but it shows that date accepts its output as an input.


Trivia: To make most commands produce locale independent output, use LANG=C some_command. In the above example LANG=C date should work as well.

Related Question