A solution with the big DateTime module family

#!/usr/bin/perl -l # 08/24/06 09:30 => Thursday, August 24th 9:30am use DateTime::Format::Strptime; my $format_input = '%D %H:%M'; my $format_output = '%A, %B %eth %l:%M%P'; my $Strp = new DateTime::Format::Strptime( pattern => $format_input, locale => 'en_US', time_zone => 'America/New_York', ); ## Start my $date_time = '08/24/06 09:30'; # 1. Get the date/tim +e my $dt = $Strp->parse_datetime( $date ); # 2. Convert to DateT +ime object my $newtime = $dt->strftime( $format_output ); # 3. Output the new d +ate/time print $newtime; ## End
Updated: Solution with the Date::Format and Date::Parse modules
#!/usr/bin/perl -l # 08/24/06 09:30 => Thursday, August 24th 9:30am use Date::Parse; use Date::Format; use Date::Language; my $format = '%A, %B %o %l:%M%P'; my $language = Date::Language->new('English'); ## Start my $date_time = '08/24/06 09:30'; my $time = $language->str2time( $date_time ); # 1. Parse my $newtime = $language->time2str( $format, $time ); # 2. Output print $newtime; ## End

In reply to Re: changing time date format. by explorer
in thread changing time date format. by pglinx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.