Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
The Posix-module has a very nice function called strftime() that is capable of formatting dates and times to a human readable format.

But ... the manpage is not very descriptive. It tells you nothing about the meanings of the parameters in the format string.

Unix/Linux users can read about them by typing
$ date --help
(thanks blokhead for advising me on that), but Windows users are lost.

Therefore, in the hope it will help somebody*, i post this little script, that can serve both as a reference and as an example.
use strict; use POSIX qw(strftime); print strftime qq{ a: Day of Week (short, text) %a A: Day of Week (long, text) %A b: Monthname (short, text) %b B: Monthname (long, text) %B c: Full datetime (number, long) %c d: Day (number) %d H: Hour (24 hour) (number) %H I: Hour (12 hour) (number) %I j: Day of year (number) %j m: Month (number) %m M: Minutes (number) %M p: am/pm/empty (text) %p S: Seconds (number) %S U: Week of Year (number) %U w: Day of week (number) %w W: Week of Year (number) %W x: date (number) %x X: time (number) %X y: year (short, number) %y Y: year (long, number) %Y Z: timezone (text) %Z }, localtime;

Notes:
The parameters %U and %W, are not identical. %U starts counting the Week Of Year at sundays, %W starts counting on mondays.
The %p parameter can be empty, depending on the locale of the system.

*and for my own convenience

Update: corrected typo for %M
Update: corrected typo for %I (thanks bmann)
Update: retitled node from "strftime reference" to "strftime reference for win32"


holli, /regexed monk/

In reply to strftime reference for Win32 by holli

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (5)
    As of 2014-12-20 15:58 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (96 votes), past polls