summaryrefslogtreecommitdiff
path: root/unixtime.pl
diff options
context:
space:
mode:
Diffstat (limited to 'unixtime.pl')
-rwxr-xr-xunixtime.pl23
1 files changed, 22 insertions, 1 deletions
diff --git a/unixtime.pl b/unixtime.pl
index 08a987a..f47cf9f 100755
--- a/unixtime.pl
+++ b/unixtime.pl
@@ -1,4 +1,25 @@
#!/usr/bin/perl
use POSIX qw( strftime );
+use Time::HiRes qw( gettimeofday );
+
+if (defined $ARGV[0]) {
+ if ($ARGV[1] eq "ms") {
+ #Convert from timestamp in milliseconds to date
+ $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") {
+ #Print current millisecond unix timestamp
+ ($seconds, $microseconds) = gettimeofday;
+ $milliseconds = substr $microseconds, 0, 3;
+ print $seconds . $milliseconds . "\n";
+ } else {
+ #Convert standard unix timestamp to date
+ print strftime('%a %b %e %H:%M:%S %Z %Y', localtime( $ARGV[0] ) ) . "\n";
+ }
+} else {
+ #Print current standard unix timestamp
+ print time . "\n";
+}
-print strftime('%a %b %e %H:%M:%S %Z %Y', localtime( $ARGV[0] ) ) . "\n";