Reputation: 843
I need to convert this date format to epoch : 03/Apr/2016 14:22:59 the command
date -d "03/Apr/2016 14:22:59" +"%s"
will return :
date: invalid date ‘03/Apr/2016 14:22:59
Anyone can help me format it in a way it become recognizable by date -d ? Thanks in advance.
Upvotes: 1
Views: 921
Reputation: 497
Info page for date input formats can be shown with following command:
info date "Date input formats"
Unfortunately your date format is not supported by date
. You can however convert your string into format that is supported for example like this:
date -d "$(echo '03/Apr/2016 14:22:59' | tr -s "/" "-")" +"%s"
To provide information about which kind of input strings can be used for date
command I will write here a short summary:
date -d "@1513936964"
date -d "tomorrow 10:00:30PM"
date -d "03 April 2016 14:22:59"
date -d "04/03/2016 14:22:59"
date -d "03-Apr-2016 14:22:59"
date -d "2016-04-03 14:22:59.00"
date -d "PDT now"
date -d "$(date -d "2017-12-24") -1 year" +"%A"
Upvotes: 2
Reputation: 4366
Using Python:
python -c 'from time import strftime, strptime;print strftime("%s", strptime("03/Apr/2016 14:22:59", "%d/%b/%Y %H:%M:%S"))'
Upvotes: 1
Reputation: 241908
Perl to the rescue:
perl -MTime::Piece -e 'print Time::Piece
->strptime("03/Apr/2016 14:22:59", "%d/%b/%Y %H:%M:%S")
->epoch'
Upvotes: 2