Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Format XML Atom DateTime

by tobyink (Canon)
on Feb 26, 2012 at 08:19 UTC ( [id://956228]=note: print w/replies, xml ) Need Help??


in reply to Format XML Atom DateTime

This does the trick:

use 5.010; use DateTime::Format::ISO8601; say DateTime::Format::ISO8601 -> parse_datetime('2012-02-25T18:48:34.835-05:00') -> strftime('%F %T');

However, note that you're dropping the time zone altogether! Unless you know that all the Atom entries have been posted from the same time zone, this is a bad idea.

An entry dated 2012-02-25T12:00:00+12:00 was written a full day earlier than one at 2012-02-25T12:00:00-12:00, yet using the conversion above, they'd both get formatted as 2012-02-25 12:00:00.

To solve that you could normalise them all to the same time zone before formatting. UTC is the time zone most commonly used for that purpose.

use 5.010; use DateTime::Format::ISO8601; say DateTime::Format::ISO8601 -> parse_datetime('2012-02-25T18:48:34.835-05:00') -> set_time_zone('UTC') -> strftime('%F %T');

Replies are listed 'Best First'.
Re^2: Format XML Atom DateTime
by ikegami (Patriarch) on Feb 27, 2012 at 21:31 UTC

    local would be another obvious time zone choice, but there is information loss in using it. (Some times occur twice on some days in some time zones.)

    '%F %T' might be clearer as '%Y-%m-%d %H:%M:%S'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://956228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found