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) It's functionality differs across platforms as reported in previous threads on perlmonks:
2) The documentation therefore also differs across platforms:
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) 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:
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]};
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |