{
    "mode": "perldoc",
    "parameter": "DateTime::Format::ISO8601",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/DateTime%3A%3AFormat%3A%3AISO8601/json",
    "generated": "2026-06-05T12:53:12Z",
    "synopsis": "use DateTime::Format::ISO8601;\nmy $datetimestr = '2020-07-25T11:32:31';\nmy $dt = DateTime::Format::ISO8601->parsedatetime($datetimestr);\nsay $dt;\n# This format is ambiguous and could be either a date or time, so use the\n# parsetime method.\nmy $timestr = '113231';\n$dt = DateTime::Format::ISO8601->parsetime($timestr);\nsay $dt;\n# or\nmy $iso8601 = DateTime::Format::ISO8601->new;\n$dt = $iso8601->parsedatetime($datetimestr);\nsay $dt;\n$dt = $iso8601->parsetime($timestr);\nsay $dt;\nsay DateTime::Format::ISO8601->formatdatetime($dt);",
    "sections": {
        "NAME": {
            "content": "DateTime::Format::ISO8601 - Parses ISO8601 formats\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 0.16\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use DateTime::Format::ISO8601;\n\nmy $datetimestr = '2020-07-25T11:32:31';\nmy $dt = DateTime::Format::ISO8601->parsedatetime($datetimestr);\nsay $dt;\n\n# This format is ambiguous and could be either a date or time, so use the\n# parsetime method.\nmy $timestr = '113231';\n$dt = DateTime::Format::ISO8601->parsetime($timestr);\nsay $dt;\n\n# or\n\nmy $iso8601 = DateTime::Format::ISO8601->new;\n$dt = $iso8601->parsedatetime($datetimestr);\nsay $dt;\n\n$dt = $iso8601->parsetime($timestr);\nsay $dt;\n\nsay DateTime::Format::ISO8601->formatdatetime($dt);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Parses almost all ISO8601 date and time formats. ISO8601 time-intervals will be supported in a\nlater release.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "This class provides the following methods:\n",
            "subsections": [
                {
                    "name": "Constructors",
                    "content": "DateTime::Format::ISO8601->new( ... )\nAccepts an optional hash.\n\nmy $iso8601 = DateTime::Format::ISO8601->new(\nbasedatetime => $dt,\ncutoffyear  => 42,\nlegacyyear   => 1,\n);\n\n*   basedatetime\n\nA \"DateTime\" object that will be used to fill in missing information from incomplete\ndate/time formats.\n\nThis key is optional.\n\n*   cutoffyear\n\nA integer representing the cut-off point between interpreting 2-digits years as 19xx or\n20xx.\n\n2-digit years <  cutoffyear will be interpreted as 20xx\n2-digit years >= cutoffyear will be untreated as 19xx\n\nThis key defaults to the value of \"DefaultCutOffYear\".\n\n*   legacyyear\n\nA boolean value controlling if a 2-digit year is interpreted as being in the current century\n(unless a \"basedatetime\" is set) or if \"cutoffyear\" should be used to place the year in\neither 20xx or 19xx.\n\nIf this is true, then the \"cutoffyear\" is used. If this is false, then the year is always\ninterpreted as being in the current century.\n\nThis key defaults to the value of \"DefaultLegacyYear\".\n\n$iso8601->clone\nReturns a replica of the given object.\n"
                },
                {
                    "name": "Object Methods",
                    "content": "$iso8601->basedatetime\nReturns a \"DateTime\" object if a \"basedatetime\" has been set.\n\n$iso8601->setbasedatetime( object => $object )\nAccepts a \"DateTime\" object that will be used to fill in missing information from incomplete\ndate/time formats.\n\n$iso8601->cutoffyear\nReturns a integer representing the cut-off point between interpreting 2-digits years as 19xx or\n20xx.\n\n$iso8601->setcutoffyear($int)\nAccepts a integer representing the cut-off point between interpreting 2-digits years as 19xx or\n20xx.\n\n2-digit years <  legacyyear will be interpreted as 20xx\n2-digit years >= legacyyear will be interpreted as 19xx\n\n$iso8601->legacyyear\nReturns a boolean value indicating the 2-digit year handling behavior.\n\n$iso8601->setlegacyyear($bool)\nAccepts a boolean value controlling if a 2-digit year is interpreted as being in the current\ncentury (unless a \"basedatetime\" is set) or if \"cutoffyear\" should be used to place the year\nin either 20xx or 19xx.\n"
                },
                {
                    "name": "Class Methods",
                    "content": "DateTime::Format::ISO8601->DefaultCutOffYear($int)\nAccepts a integer representing the cut-off point for 2-digit years when calling \"parse*\" as\nclass methods and the default value for \"cutoffyear\" when creating objects. If called with no\nparameters this method will return the default value for \"cutoffyear\".\n\nDateTime::Format::ISO8601->DefaultLegacyYear($bool)\nAccepts a boolean value controlling the legacy year behavior when calling \"parse*\" as class\nmethods and the default value for \"legacyyear\" when creating objects. If called with no\nparameters this method will return the default value for \"legacyyear\".\n\nParser(s)\nThese methods may be called as either class or object methods.\n\nparsedatetime\nparsetime\nPlease see the \"FORMATS\" section.\n"
                },
                {
                    "name": "Formatter",
                    "content": "This may be called as either class or object method.\n\nformatdatetime($dt)\nFormats the datetime in an ISO8601-compatible format. This differs from \"iso8601\" in DateTime by\nincluding nanoseconds/milliseconds and the correct timezone offset.\n"
                }
            ]
        },
        "FORMATS": {
            "content": "There are 6 strings that can match against date only or time only formats. The \"parsedatetime\"\nmethod will attempt to match these ambiguous strings against date only formats. If you want to\nmatch against the time only formats use the \"parsetime\" method.\n",
            "subsections": [
                {
                    "name": "Conventions",
                    "content": "*   Expanded ISO8601\n\nThese formats are supported with exactly 6 digits for the year. Support for a variable\nnumber of digits will be in a later release.\n\n*   Precision\n\nIf a format doesn't include a year all larger time unit up to and including the year are\nfilled in using the current date/time or [if set] the \"basedatetime\" object.\n\n*   Fractional time\n\nThere is no limit on the expressed precision.\n"
                },
                {
                    "name": "Supported via parsedatetime",
                    "content": "The supported formats are listed by the section of ISO 8601:2000(E) in which they appear.\n\n5.2 Dates\n*   5.2.1.1\n\nYYYYMMDD\nYYYY-MM-DD\n\n*   5.2.1.2\n\nYYYY-MM\nYYYY\nYY\n\n*   5.2.1.3\n\nYYMMDD\nYY-MM-DD"
                },
                {
                    "name": "-YYMM",
                    "content": ""
                },
                {
                    "name": "-YY-MM",
                    "content": ""
                },
                {
                    "name": "-YY",
                    "content": ""
                },
                {
                    "name": "--MMDD",
                    "content": "",
                    "long": "--MMDD"
                },
                {
                    "name": "--MM-DD",
                    "content": "",
                    "long": "--MM-DD"
                },
                {
                    "name": "--MM",
                    "content": "---DD\n\n*   5.2.1.4\n\n+[YY]YYYYMMDD\n+[YY]YYYY-MM-DD\n+[YY]YYYY-MM\n+[YY]YYYY\n+[YY]YY\n\n*   5.2.2.1\n\nYYYYDDD\nYYYY-DDD\n\n*   5.2.2.2\n\nYYDDD\nYY-DDD",
                    "long": "--MM"
                },
                {
                    "name": "-DDD",
                    "content": "*   5.2.2.3\n\n+[YY]YYYYDDD\n+[YY]YYYY-DDD\n\n*   5.2.3.1\n\nYYYYWwwD\nYYYY-Www-D\n\n*   5.2.3.2\n\nYYYYWww\nYYYY-Www\nYYWwwD\nYY-Www-D\nYYWww\nYY-Www"
                },
                {
                    "name": "-YWwwD",
                    "content": ""
                },
                {
                    "name": "-Y-Www-D",
                    "content": ""
                },
                {
                    "name": "-YWww",
                    "content": ""
                },
                {
                    "name": "-Y-Www",
                    "content": ""
                },
                {
                    "name": "-WwwD",
                    "content": ""
                },
                {
                    "name": "-Www-D",
                    "content": ""
                },
                {
                    "name": "-Www",
                    "content": ""
                },
                {
                    "name": "-W-D",
                    "content": "*   5.2.3.4\n\n+[YY]YYYYWwwD\n+[YY]YYYY-Www-D\n+[YY]YYYYWww\n+[YY]YYYY-Www\n\n5.3 Time of Day\n*   5.3.1.1 - 5.3.1.3\n\nValues can optionally be prefixed with 'T'.\n\n*   5.3.1.1\n\nhh:mm:ss\n\n*   5.3.1.2\n\nhh:mm\n\n*   5.3.1.3 - 5.3.1.4\n\nfractional (decimal) separator maybe either ',' or '.'\n\n*   5.3.1.3\n\nhhmmss,ss\nhh:mm:ss,ss\nhhmm,mm\nhh:mm,mm\nhh,hh\n\n*   5.3.1.4\n\n-mm:ss\n-mmss,s\n-mm:ss,s\n-mm,m\n--ss,s\n\n*   5.3.3 - 5.3.4.2\n\nValues can optionally be prefixed with 'T'.\n\n*   5.3.3\n\nhhmmssZ\nhh:mm:ssZ\nhhmmZ\nhh:mmZ\nhhZ\nhhmmss.ssZ\nhh:mm:ss.ssZ\n\n*   5.3.4.2\n\nhhmmss[+-]hhmm\nhh:mm:ss[+-]hh:mm\nhhmmss[+-]hh\nhh:mm:ss[+-]hh\nhhmmss.ss[+-]hhmm\nhh:mm:ss.ss[+-]hh:mm\n\n5.4 Combinations of date and time of day\n*   5.4.1\n\nYYYYMMDDThhmmss\nYYYY-MM-DDThh:mm:ss\nYYYYMMDDThhmmssZ\nYYYY-MM-DDThh:mm:ssZ\nYYYYMMDDThhmmss[+-]hhmm\nYYYY-MM-DDThh:mm:ss[+-]hh:mm\nYYYYMMDDThhmmss[+-]hh\nYYYY-MM-DDThh:mm:ss[+-]hh\n\n*   5.4.2\n\nYYYYMMDDThhmmss.ss\nYYYY-MM-DDThh:mm:ss.ss\nYYYYMMDDThhmmss.ss[+-]hh\nYYYY-MM-DDThh:mm:ss.ss[+-]hh\nYYYYMMDDThhmmss.ss[+-]hhmm\nYYYY-MM-DDThh:mm:ss.ss[+-]hh:mm\n\n*   5.4.3\n\nSupport for this section is not complete.\n\nYYYYMMDDThhmm\nYYYY-MM-DDThh:mm\nYYYYMMDDThhmmZ\nYYYY-MM-DDThh:mmZ\nYYYYDDDThhmm\nYYYY-DDDThh:mm\nYYYYDDDThhmmZ\nYYYY-DDDThh:mmZ\nYYYYWwwDThhmm[+-]hhmm\nYYYY-Www-DThh:mm[+-]hh\n\n5.5 Time-Intervals\nThese are not currently supported\n"
                },
                {
                    "name": "Supported via parsetime",
                    "content": "5.3.1.1 - 5.3.1.3\nValues can optionally be prefixed with 'T'.\n\n*   5.3.1.1\n\nhhmmss\n\n*   5.3.1.2\n\nhhmm\nhh\n\n*   5.3.1.4\n"
                },
                {
                    "name": "-mmss",
                    "content": ""
                },
                {
                    "name": "-mm",
                    "content": ""
                },
                {
                    "name": "--ss",
                    "content": "",
                    "long": "--ss"
                }
            ]
        },
        "STANDARDS DOCUMENT": {
            "content": "",
            "subsections": [
                {
                    "name": "Title",
                    "content": "ISO8601:2000(E)\nData elements and interchange formats - information exchange -\nRepresentation of dates and times\nSecond edition 2000-12-15\n"
                },
                {
                    "name": "Reference Number",
                    "content": "ISO/TC 154 N 362\n"
                }
            ]
        },
        "CREDITS": {
            "content": "Iain 'Spoon' Truskett (SPOON) who wrote DateTime::Format::Builder. That has grown into *The\nVacuum Energy Powered \"Swiss Army\" Katana* of date and time parsing. This module was inspired by\nand conceived in honor of Iain's work.\n\nTom Phoenix (PHOENIX) and PDX.pm for helping me solve the ISO week conversion bug. Not by fixing\nthe code but motivation me to fix it so I could participate in a game of \"Zendo\".\n\nJonathan Leffler (JOHNL) for reporting a test bug.\n\nKelly McCauley for a patch to add 8 missing formats.\n\nAlasdair Allan (AALLAN) for complaining about excessive test execution time.\n\nEveryone at the DateTime \"Asylum\".\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "*   DateTime\n\n*   DateTime::Format::Builder\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "Bugs may be submitted at <https://github.com/houseabsolute/DateTime-Format-ISO8601/issues>.\n\nI am also usually active on IRC as 'autarch' on \"irc://irc.perl.org\".\n",
            "subsections": []
        },
        "SOURCE": {
            "content": "The source code repository for DateTime-Format-ISO8601 can be found at\n<https://github.com/houseabsolute/DateTime-Format-ISO8601>.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "*   Joshua Hoblitt <josh@hoblitt.com>\n\n*   Dave Rolsky <autarch@urth.org>\n",
            "subsections": []
        },
        "CONTRIBUTORS": {
            "content": "*   Doug Bell <doug@preaction.me>\n\n*   joe <draxil@gmail.com>\n\n*   Liam Widdowson <lbw@telstra.com>\n\n*   Thomas Klausner <domm@plix.at>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is copyright (c) 2021 by Joshua Hoblitt.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n\nThe full text of the license can be found in the LICENSE file included with this distribution.\n",
            "subsections": []
        }
    },
    "summary": "DateTime::Format::ISO8601 - Parses ISO8601 formats",
    "flags": [],
    "examples": [],
    "see_also": []
}