Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Answer: How can I format the output of localtime?

by Zaxo (Archbishop)
on Feb 12, 2004 at 03:48 UTC ( #328472=categorized answer: print w/replies, xml ) Need Help??

Q&A > dates and times > How can I format the output of localtime? - Answer contributed by Zaxo

The most convenient formatter for localtime output is &POSIX::strftime. It is similar to an sprintf call, taking a format string as its first argument, and a localtime compatible list as the remaining arguments. The formats are specialized for time units, and extract the strings without need for displacements in the data. The complete list of formats is given in man 3 strftime. A locale-sensitive date can be formatted with the "%x" format string:
use POSIX 'strftime'; my $datestring = strftime 'Today is %x.', localtime; print $datestring, $/;
The format inquired of is given (with leading zeros) by the "%D" format string. Full names of months and days in the language of the current locale are given by the "%B" and "%A" formats, and their abbreviations by "%b" and "%a".

Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2020-10-31 08:34 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (287 votes). Check out past polls.