in reply to Date to Epoch

I have found a way to do this but it is messy:

perl -MPOSIX -MTime::Local -se 'print scalar timelocal($a, $b, $c, $d, $e, $f)' -- -a=$sec -b=$min -c=$hour -d=$day -e=$month -f=$year

Is there a more simpler approach as the one proposed earlier?

Replies are listed 'Best First'.
Re^2: Date to Epoch
by haukex (Archbishop) on Mar 20, 2018 at 15:11 UTC

    The root node shows the date as a single string (without seconds), but now you have what look like individual bash variables $sec, $min, etc. - where did those come from? Perhaps you could provide us with more context (surrounding code, etc.). See also I know what I mean. Why don't you?

      My apology

      Running:

      ls -oglE <file_name> | awk '{print $4":"$5}' | cut -d. -f1

      will provide with me a date format of: 2018-03-15:09:25:15

      I can then parse this data and assign it to individual variables like seconds, minutes, hours, day, month, year

      But I was hoping to find a simple one line solution to take a format of "Mar 15 09:25:29 2018" and get an epoch time