diff options
author | Joe Robinson <joe@lc8n.com> | 2017-07-12 14:22:38 +0100 |
---|---|---|
committer | Joe Robinson <joe@lc8n.com> | 2017-07-12 14:22:38 +0100 |
commit | a46542b43eb800d3d807e1ce6c1e15482a113684 (patch) | |
tree | 59a9c8094e9a5aaf182e536e70d20c7840225a9a | |
parent | ba7417df7cdd5f291d8cc359c9c5450ffadff905 (diff) |
Add options to convert and print milliseconds, and to show the current unixtime
-rwxr-xr-x | unixtime.pl | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/unixtime.pl b/unixtime.pl index 08a987a..d6bb1d8 100755 --- a/unixtime.pl +++ b/unixtime.pl @@ -1,4 +1,21 @@ #!/usr/bin/perl use POSIX qw( strftime ); +use Time::HiRes qw( gettimeofday ); + +if (defined $ARGV[0]) { + if ($ARGV[1] eq "ms") { + $seconds = substr $ARGV[0], 0, 10; + $milliseconds = substr $ARGV[0], 10, 3; + $date = strftime('%a %b %e %H:%M:%S:'.$milliseconds.' %Z %Y', localtime( $seconds ) ) . "\n"; + print $date; + } elsif ($ARGV[0] eq "ms") { + ($seconds, $microseconds) = gettimeofday; + $milliseconds = substr $microseconds, 0, 3; + print $seconds . $milliseconds . "\n"; + } else { + print strftime('%a %b %e %H:%M:%S %Z %Y', localtime( $ARGV[0] ) ) . "\n"; + } +} else { + print time . "\n"; +} -print strftime('%a %b %e %H:%M:%S %Z %Y', localtime( $ARGV[0] ) ) . "\n"; |