I am trying to convert a date string in continental Portuguese back to epoch time using bash. My default locale is en_US.utf8

My example string is Mai 12 06:58:47 WEST 2015

I have already tried doing:

LC_TIME="pt_PT.utf8" date --date="Mai 12 06:58:47 WEST 2015" +%s    
LC_ALL="pt_PT.utf8" date --date="Mai 12 06:58:47 WEST 2015" +%s

First command gives back the error date: invalid date and second command returns the same error in Portuguese.

I also tried with pt_PT which does not makes sense, I think, as I do not have that locale installed.

How can I do it?


Sadly, with GNU date this is not currently possible. From the docs:


Display the date and time specified in datestr instead of the current date and time. datestr can be in almost any common format. It can contain month names, time zones, ‘am’ and ‘pm’, ‘yesterday’, etc. For example, --date="2004-02-27 14:19:13.489392193 +0530" specifies the instant of time that is 489,392,193 nanoseconds after February 27, 2004 at 2:19:13 PM in a time zone that is 5 hours and 30 minutes east of UTC.
Note: input currently must be in locale independent format. E.g., the LC_TIME=C below is needed to print back the correct date in many locales:

date -d "$(LC_TIME=C date)"

(emphases added)

  • Nice catch. I had a quick look at the man page, and did not spot that. Thanks for the help. – Rui F Ribeiro Jun 9 '17 at 17:29

GNU date only understands the English ones,

You can try ksh93:

$ LC_ALL=pt_PT.UTF-8 ksh -c 'printf "%(%F)T\n" "Mai 12 06:58:47 WEST 2015"'

Or zsh:

zmodload zsh/datetime
strftime -rs t "%b %d %H:%M:%S %Z %Y" "May 12 06:58:47 WEST 2015"
strftime %F $t
  • This one in korn shell is a nice alternative; for other people besides @Stéphane, yes, I do know other languages/utils are able to process it. – Rui F Ribeiro Jun 9 '17 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.