Turning given date to epoch

i can probably script this in bash, but, i was wondering, does anyone know of a simple way to translate a given time to epoch?

date -d@"29/Oct/2013:17:53:11"

the user would specify the date: 29/Oct/2013:17:53:11

and the script will simply interpret that to epoch: 1348838383 (this is just an example)

local to epoch

$ date -d"2013-10-29 17:53:11" +%s
1383049391

epoch to local

$ date -d@1348838383
Fri Sep 28 18:49:43 IST 2012

Or if you have ksh93, use builtin printf %T option:

#!/bin/ksh93

printf "%(%s)T" "29/Oct/2013:17:53:11"
1 Like
date --date="$(echo "29/Oct/2013:17:53:11" | sed -e 's/\// /g;s/:/ /')" +%s
1383083591
2 Likes

To use -d date option you will need to replace slash with hyphen and get rid of colon between year and hour something like this in bash:

$ D="29/Oct/2013:17:53:11"
$ D=${D//\//-}
$ date -d "${D/:/ }" +%s
1383033191
1 Like