Here is a shell function that does not require perl:
function d2ts
{
typeset d=$(echo "$@" | tr -d ':- ' | sed 's/..$/.&/')
typeset t=$(mktemp) || return -1
typeset s=$(touch -t $d $t 2>&1) || { rm $t ; return -1 ; }
[ -n "$s" ] && { rm $t ; return -1 ; }
truss -f -v 'lstat,lstat64' ls -d $t 2>&1 | nawk '/mt =/ {printf "%d\n",$10}'
rm $t
}
$ d2ts 2013-04-29 08:17:58
1367216278
Please note that the return value depends on your time zone.
$ TZ=GMT d2ts 2013-04-29 08:17:58
1367223478
How it works:
- The first line converts the parameters to a format suitable for
touch
(here "2013-04-29 - 08:17:58 "->" 201304290817.58 ")
- , , ..
ls
,