Re: How to format timestamps M/D/Y h:mm:ss AMPM (e.g., 4/8/2013 6:09:03 PM)?by Jim (Curate)
|on May 14, 2013 at 04:07 UTC||Need Help??|
(I'm replying to my own post because I believe I've found the best general solution to my problem.)
Once I'd figured out that I could use DateTime::format_cldr() to render the timestamps in the required format, it seemed incongruous to be parsing them using DateTime::Format::Strptime. The new carpet made me realize I needed to replace the drapes. I was doing this…
pattern => '%Y%m%d %H:%M:%S',
my $pattern = 'M/d/y h:mm:ss a';
…in two successive statements, which is inelegant. So I decided to use CLDR to parse the timestamps as well as to format them. Doing this neatens and tightens the code.
8/5/2004 6:31:00 PM 1/6/2005 10:54:27 AM 3/2/2005 1:23:35 AM 8/8/2010 8:00:16 PM 5/1/2011 6:09:44 PM 9/9/2011 8:02:42 PM 4/8/2013 6:09:03 PM