Question:
Format date in Perl - MM/DD/YYYY?
1970-01-01 00:00:00 UTC
Format date in Perl - MM/DD/YYYY?
Four answers:
?
2016-11-05 11:02:14 UTC
Perl Date
2015-08-17 03:19:29 UTC
This Site Might Help You.



RE:

Format date in Perl - MM/DD/YYYY?

I just want to grab the current date in Perl in the format MM/DD/YYYY, how can I do this in Perl?
martinthurn
2007-09-10 12:17:53 UTC
use Date::Manip;

my $s = &UnixDate('now', '%m/%d/%Y');

print "$s\n";
Dave Cardwell
2007-09-11 08:38:33 UTC
The method without any external modules:



my $mmddyyyy = sprintf "%02d/%02d/%d",

(localtime)[4] + 1, # months

(localtime)[3], # days

(localtime)[5] + 1900; # years





The more maintainable way:



use POSIX qw( strftime );

my $mmddyyyy = strftime("%m/%d/%Y", localtime);





The POSIX module comes with the standard distribution of Perl, so should never need installing separately. As a result it is very fast and extremely portable.





Best wishes,

Dave Cardwell.

http://davecardwell.co.uk/perl/


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...