Search code examples
bashunixdate

Forcing "date" to use a locale other than the machine default


Is there a way to force the *nix command "date" to output in a specific format independent of the local? For example, if I call "date -u" today, on a US machine I get:

Mon Oct 15 13:15:29 UTC 2012

but on a German machine I get:

Mo 15. Okt 13:15:31 UTC 2012

Solution

  • Sure, you can always specify the format yourself:

    date +%a, %b %d
    

    or you can use a temporary environmental variable:

    :~$ LC_ALL=de_DE.utf8 date
    Mo 15. Okt 15:34:11 CEST 2012
    :~$ date
    Mon Oct 15 15:33:24 CEST 2012
    

    As you see, only the first command is run with the German locale.