python--pyiso8601

Source: Internet
Author: User

The module is not a Python built-in module that complements the ISO 8601 parsing for Python-converting common ISO 8601 date characters into a Python datetime object.

  Installation

Install iso8601

  Use

>>> Import iso8601

  Example

>>> Import iso8601>>> iso8601.parse_date ("2007-01-25t12:00:00z") Datetime.datetime (2007, 1, 25, 12, 0, tzinfo=<iso8601. utc>) >>>

  Format

You can parse either the full date + time pattern string, or just the string containing the date, both of which return a DateTime instance, but the returned time defaults to 0 and the returned day/month defaults to 1.

  Date

    • Yyyy-mm-dd
    • YYYYMMDD
    • YYYY-MM (Day defaults to 1)
    • YYYY (month and day are defaulted to 1)

  Time

    • Hh:mm:ss.nn
    • Hhmmss.nn
    • HH:MM (second default is 0)
    • HHMM (second default is 0)
    • HH (both minute and second default to 0)

  Time

    • Default is UTC
    • Z (UTC)
    • +/-hh:mm
    • +/-hhmm
    • +/-hh

  The difference from ISO 8601

    • You can use spaces ("") instead of "T" to differentiate between dates and times
    • The days and months below 10 are not identified by the number "0", for example (2 instead of 02).
    • Time zone defaults to UTC

  

Api

Iso8601.parse_date (DateString, default_timezone=<iso8601. utc>)

Converts text in ISO 8601 format to a Python datetime object.

  Parameters

    • datestring-- The date string to parse, which can also contain time zone information
    • Default_timezone --time zone information, a datetime tzinfo instance that is used when no time zone information is included in the parameter datestring . If set to None returns a simple datetime object.

  return value
  
A Datetime.datetime instance

  

Abnormal

Exception iso8601. ParseError

Thrown parseerror when iso8601.parse_date () resolves an error or cannot construct a DateTime instance

python--pyiso8601

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.