Reputation: 79
I'm looking for a quick script or time/date module to convert the below Unix format
[randy@go1server03 /ftp/device]$ date.
Thu Apr 24 13:48:28 UTC 2014
to something like only 04-24
, where 04 is month April and 24 is the date. Is their any quick and dirty way to do this?
Thanks in advance
Upvotes: 1
Views: 441
Reputation: 98921
You can use this:
#!/usr/local/bin/perl
use strict;
use warnings;
use Time::Piece;
my $date = localtime->strftime('%m-%d');
print $date;
DEMO: http://ideone.com/K1hVy8
Upvotes: 5
Reputation: 24063
I recommend using the core module Time::Piece
for date manipulation in Perl.
Here's a one-liner (using the current time):
perl -MTime::Piece -wE '$t = Time::Piece->new; say $t->strftime( q{%m-%d} );'
Or to do this in a script:
use strict;
use warnings;
use 5.010;
use Time::Piece;
my $t = Time::Piece->new;
say $t->strftime('%m-%d');
Upvotes: 3