I've used the following two perl command lines successfully:

perl -e 'use Time::Local; print timelocal(7,51,10,22,3,2014), "\n";'

which returns 1398163867, and

perl -e 'print scalar(localtime(1398163867)), "\n"'

which returns Tue Apr 22 10:51:07 2014

What I would like to do is replace 7,51,10,22,3,2014, and 1398163867 with a variable containing those values. How can I do this?

1 Answer 1


If you mean a shell variable:

perl -MTime::Local -le 'print timelocal split ",", shift' -- "$t"

perl -le 'print scalar localtime shift' -- "$t"
  • That's exactly what I was looking for. Thanks!
    – PCO
    Apr 22, 2014 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.