What is your preferred platform independent alternative to POSIX->strftime?

I often recommend POSIX->strftime on forums since it's part of CORE, and therefore won't require any module installation. However, it does fail in a few ways:

  1. 1) It's functionality differs across platforms as reported in previous threads on perlmonks:

    1. [Explained] Platform-dependent behavior observed in POSIX::strftime
    2. strftime reference for Win32
  2. 2) The documentation therefore also differs across platforms:

    1. unix: "man strftime"
    2. windows: MSDN strftime

    I've often used the "I'm feeling lucky" reference for strftime in a pinch, but that doesn't match any OS I use completely.

  3. 3) It fails transparently.

    Whenever an unrecognized format is used, it simply doesn't parse the string. To debug this you must attempt to use each specifier individually to determine which one failed.

I even attempted to limit myself to the "safer" specifiers reported by POSIX, aAbBcdHIjmMpSUwWxXyYZ%, but they aren't platform independent either.

I'm therefore looking for suggestions of CPAN alternatives that will work the same regardless of platform. Ideally it would be able to be a drop in replacement for previous uses of my $date = strftime $fmt, localtime;. The two that I'm currently examining are:

  1. Alternative 1) Date::Format: has a strftime function but annoyingly is prototyped to require an array as the 2nd argument, my $date = strftime $fmt, @{[localtime]};

  2. Alternative 2) DateTime: Does work as my $date = DateTime->now->strftime($fmt);, but doesn't have a constructor that accepts the 'struct tm' data structure returned by localtime

Do you have a preferred module for formatting dates that you recommend to programmers on forums? Is the platform dependent nature of POSIX a non-issue, or is it good that I want a module that will work the same regardless of the local environment?


In reply to CPAN alternative to POSIX strftime by wind

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.