Skip to content

Instantly share code, notes, and snippets.

@michel47
Created April 19, 2022 10:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
getting unix time from date (perl)
#!/usr/bin/perl
my $date = '4/12/2022 10:55:24';
printf "%u %s\n",&unixtime($date);
sub unixtime {
use Time::Local qw/timelocal/; # require "timelocal.pl";
my $date = shift;
my ($sec,$min,$hour,$mon,$mday,$year);
if ($date =~ m/ /) {
($date, $time) = split(' ',$date);
($hour,$min,$sec) = split ':', $time;
}
($mon,$mday,$year) = split '/', $date;
if ($mon > 12) { # date of form 1997/7/28 (EU style)
($year,$mon,$mday) = split '/', $date;
}
my $tics = timelocal($sec,$min,$hour,$mday,$mon-1,$year);
return $tics
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment