Skip to content

Instantly share code, notes, and snippets.

@tron1point0
Created March 2, 2012 16:03
Show Gist options
  • Save tron1point0/1959334 to your computer and use it in GitHub Desktop.
Save tron1point0/1959334 to your computer and use it in GitHub Desktop.
You type stuff as arguments, it gives you the local time
#!/usr/bin/env perl
use v5.14;
use warnings;
use Time::Format qw(time_format);
use Time::ParseDate;
die <<END if $ARGV[0] && $ARGV[0] =~ m/-h(?:elp)?/;
$0: Fuzzy time conversion to localtime
Usage:
$0 time [--] [format]
`time` can be any string that Time::ParseDate accepts
`format` can be any string that Time::Format::time_format accepts
END
my @time;
push @time, shift(@ARGV) while $ARGV[0] && $ARGV[0] ne '--';
my $timestr = join ' ',@time;
my $time = parsedate($timestr);
shift(@ARGV) if defined $ARGV[0] && $ARGV[0] eq '--';
my $formatstr = join(' ',@ARGV) || 'yyyy-mm{on}-dd hh:mm{in}:ss tz';
say time_format $formatstr, $time;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment