Skip to Content
Modern Python Standard Library Cookbook
book

Modern Python Standard Library Cookbook

by Alessandro Molina
August 2018
Intermediate to advanced
366 pages
10h 14m
English
Packt Publishing
Content preview from Modern Python Standard Library Cookbook

Parsing dates

When receiving a datetime from another software or from a user, it will probably be in a string format. Formats such as JSON don't even define how a date should be represented, but it's usually a best practice to provide those in the ISO 8601 format.

The ISO 8601 format is usually defined as [YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]+-[TZ], for example 2018-03-19T22:00+0100 would refer to March 19 at 10 P.M. on the UTC+01:00 time zone.

ISO 8601 conveys all the information you need to represent a date and time, so it's a good way to marshal a datetime and send it across a network.

Sadly, it has many oddities (for example, the +00 time zone can also be written as Z, or you can omit the : between hours, minutes, and seconds), so parsing it ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Matthew Wilkes

Publisher Resources

ISBN: 9781788830829Supplemental Content