bigjoe11a has asked for the wisdom of the Perl Monks concerning the following question:

Does any one have an idea on formating the date and time. I tryed some samples and well, I just get weard things, any way. I would like to try for some thing like this Thurs at 2:00pm on 06/01/2005 I hope some one has an idea. and be able to return a value as of $date Bigjoe

Replies are listed 'Best First'.
Re: Formating Date and Time
by Zaxo (Archbishop) on Jun 24, 2005 at 05:05 UTC

    POSIX::strftime() is the way I like best. It uses formats similar to sprintf to write various time quantities from the time list returned by localtime. See man 3 strftime for a list of the format tags.

    After Compline,
    Zaxo

Re: Formating Date and Time
by ercparker (Hermit) on Jun 24, 2005 at 06:13 UTC
    You can format the date and time with:
    use POSIX qw(strftime); print strftime("%a at %I:%M%p on %m/%d/%Y", localtime());
    I hope that helped
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Formating Date and Time
by doran (Deacon) on Jun 24, 2005 at 06:02 UTC

      Date::Calc is big if you use it all, but you can designate which routines you want to pull in:

      use Date::Calc qw( Days_in_Year Days_in_Month ... );

      (right from the doc)


      —Brad
      "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
Re: Formating Date and Time
by rev_1318 (Chaplain) on Jun 24, 2005 at 07:50 UTC
Re: Formating Date and Time
by bradcathey (Prior) on Jun 24, 2005 at 12:07 UTC

    Can you show us what you have tried? I'd like to see some code. Thanks.


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
      Brad, Yes I have. heres one that I been playing with, just can get it to work

      # $the_date=???; $date=localtime(); #This is the one I'm using now

      This is the one I want to use

      $date = &datetime; sub datetime { local(@t, $day, $month, $ap, $t1, $date); @t=localtime(time); $day=('Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat')[$t[6]]; $month=('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')[$t[4]]; if($t[2] > 12) { $t[2]-=12; $ap='pm'; } else {$ap='am';} $t1=sprintf("%.2d", $t[1]); $yr=2000+$t[5]; # wkday mo moday yr hr min am/pm $date="$day $month $t[3], $yr, $t[2]:$t1 $ap"; return $date; }

      g0n - added code tags