Tuesday, 15 April 2014

sh - Bash convert string to timestamp -



sh - Bash convert string to timestamp -

i have string in format 20141225093000 represents dec 25, 2014 09:30:00 , want convert original format unix timestamp format can time operations on it.how in bash?

i can parse out values expr hoping able identify format yyyymmddhhmmss , convert based on that.

with gnu date, can convert yyyy-mm-ddthh:mm:ss epoch time (seconds since 1-1-1970) easily, so:

date -d '2014-12-25t09:30:00' +%s

to starting without delimiters:

in=20141225093000 rfc_form="${in:0:4}-${in:4:2}-${in:6:2}t${in:8:2}:${in:10:2}:${in:12:2}" epoch_time=$(date -d "$rfc_form" +%s)

bash sh

No comments:

Post a Comment