Created
April 19, 2022 10:27
-
-
Save michel47/28885708744ee1dbdb46422f39e305a1 to your computer and use it in GitHub Desktop.
getting unix time from date (perl)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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