in reply to Date to Epoch
perl -MPOSIX -e 'print strptime(<stdin>, "%s")'
For some reason, Perl's POSIX does not provide strptime, you'd need to install and use POSIX::strptime.
But if you have or can install the module Time::Piece (in core since 5.10), you can use its Time::Piece->strptime(STRING, FORMAT), it has a nicer interface.
Update:
$ echo "Mar 20 2018 09:00" | perl -wMstrict -MTime::Piece -nle 'print +Time::Piece->strptime($_,"%b %d %Y %H:%M")->epoch' 1521536400
If you want to use POSIX::strptime, you should also look into mktime, although at that point I'd really recommend using a better module. I usually use DateTime because it supports almost everything you'd need, but for simple tasks Time::Piece is enough.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Date to Epoch (updated)
by ikegami (Patriarch) on Mar 20, 2018 at 20:33 UTC | |
|
Re^2: Date to Epoch (updated)
by Anonymous Monk on Mar 20, 2018 at 14:33 UTC | |
by haukex (Archbishop) on Mar 20, 2018 at 14:59 UTC | |
by Anonymous Monk on Mar 20, 2018 at 14:35 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |