Convert a string to epoch time

Team,

I am working on a shell script and i am extracting a date string in "SunOS server" with below format.

Mon Jan  21 04:13:48 EST 2021

Can you please assist me the best way to convert the extracted string to epoch time like "date +%s" in Linux.

Thanks in advance

Time::Local is a core module and so should be part of your Perl distribution.

This code makes NO allowance for time zone and so if you need additional timezone handling you'd need to use Date::Manip or a similar module, this is not a core module however.

 perl -MTime::Local -e '%mon=(Jan=>0,Feb=>1,Mar=>2,Apr=>3,May=>5,Jun=>6,Jul=>7,Aug=>8,Sep=>9,Oct=>10,Nov=>11,Dec=>12);$date=join("\ ",@ARGV);print timelocal($5,$4,$3,$2,$mon{$1},$7-1900),"\n" if($date=~/\w{3}\s+(\S{3})\s+(\d+)\s(\d+):(\d+):(\d+)\s(\S+)\s(\d+)/)'  Mon Jan  21 04:13:48 EST 2021
1611202428

ETA, you could modify the above to capture the timezone string and set ENV{TZ} to this value, then set $ENV{TZ} to the required output time zone (eg. GMT) for output before printing.