{
    "mode": "perldoc",
    "parameter": "DateTime::Format::Strptime",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/DateTime%3A%3AFormat%3A%3AStrptime/json",
    "generated": "2026-06-16T03:07:34Z",
    "synopsis": "use DateTime::Format::Strptime;\nmy $strp = DateTime::Format::Strptime->new(\npattern   => '%T',\nlocale    => 'enAU',\ntimezone => 'Australia/Melbourne',\n);\nmy $dt = $strp->parsedatetime('23:16:42');\n$strp->formatdatetime($dt);\n# 23:16:42\n# Croak when things go wrong:\nmy $strp = DateTime::Format::Strptime->new(\npattern   => '%T',\nlocale    => 'enAU',\ntimezone => 'Australia/Melbourne',\nonerror  => 'croak',\n);\n# Do something else when things go wrong:\nmy $strp = DateTime::Format::Strptime->new(\npattern   => '%T',\nlocale    => 'enAU',\ntimezone => 'Australia/Melbourne',\nonerror  => \\&phonepolice,\n);",
    "sections": {
        "NAME": {
            "content": "DateTime::Format::Strptime - Parse and format strp and strf time patterns\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 1.79\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use DateTime::Format::Strptime;\n\nmy $strp = DateTime::Format::Strptime->new(\npattern   => '%T',\nlocale    => 'enAU',\ntimezone => 'Australia/Melbourne',\n);\n\nmy $dt = $strp->parsedatetime('23:16:42');\n\n$strp->formatdatetime($dt);\n\n# 23:16:42\n\n# Croak when things go wrong:\nmy $strp = DateTime::Format::Strptime->new(\npattern   => '%T',\nlocale    => 'enAU',\ntimezone => 'Australia/Melbourne',\nonerror  => 'croak',\n);\n\n# Do something else when things go wrong:\nmy $strp = DateTime::Format::Strptime->new(\npattern   => '%T',\nlocale    => 'enAU',\ntimezone => 'Australia/Melbourne',\nonerror  => \\&phonepolice,\n);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module implements most of strptime(3), the POSIX function that is the reverse of",
            "subsections": [
                {
                    "name": "strftime",
                    "content": "string, \"strptime\" takes a string and a pattern and returns the \"DateTime\" object associated.\n"
                }
            ]
        },
        "METHODS": {
            "content": "This class offers the following methods.\n\nDateTime::Format::Strptime->new(%args)\nThis methods creates a new object. It accepts the following arguments:\n\n*   pattern\n\nThis is the pattern to use for parsing. This is required.\n\n*   strict\n\nThis is a boolean which disables or enables strict matching mode.\n\nBy default, this module turns your pattern into a regex that will match anywhere in a\nstring. So given the pattern \"%Y%m%d%H%M%S\" it will match a string like 20161214233712.\nHowever, this also means that a this pattern will match any string that contains 14 or more\nnumbers! This behavior can be very surprising.\n\nIf you enable strict mode, then the generated regex is wrapped in boundary checks of the\nform \"/(?:\\A|\\b)...(?:\\b|\\z/)\". These checks ensure that the pattern will only match when\nat the beginning or end of a string, or when it is separated by other text with a word\nboundary (\"\\w\" versus \"\\W\").\n\nBy default, strict mode is off. This is done for backwards compatibility. Future releases\nmay turn it on by default, as it produces less surprising behavior in many cases.\n\nBecause the default may change in the future, you are strongly encouraged to explicitly set\nthis when constructing all \"DateTime::Format::Strptime\" objects.\n\n*   timezone\n\nThe default time zone to use for objects returned from parsing.\n\n*   zonemap\n\nSome time zone abbreviations are ambiguous (e.g. PST, EST, EDT). By default, the parser will\ndie when it parses an ambiguous abbreviation. You may specify a \"zonemap\" parameter as a\nhashref to map zone abbreviations however you like:\n\nzonemap => { PST => '-0800', EST => '-0600' }\n\nNote that you can also override non-ambiguous mappings if you want to as well.\n\n*   locale\n\nThe locale to use for objects returned from parsing.\n\n*   onerror\n\nThis can be one of 'undef' (the string, not an \"undef\"), 'croak', or a subroutine reference.\n\n*       'undef'\n\nThis is the default behavior. The module will return \"undef\" on errors. The error\ncan be accessed using the \"$object->errmsg\" method. This is the ideal behaviour for\ninteractive use where a user might provide an illegal pattern or a date that doesn't\nmatch the pattern.\n\n*       'croak'\n\nThe module will croak with an error message on errors.\n\n*       sub{...} or \\&subname\n\nWhen given a code ref, the module will call that sub on errors. The sub receives two\nparameters: the object and the error message.\n\nIf your sub does not die, then the formatter will continue on as if \"onerror\" was\n'undef'.\n\n$strptime->parsedatetime($string)\nGiven a string in the pattern specified in the constructor, this method will return a new\n\"DateTime\" object.\n\nIf given a string that doesn't match the pattern, the formatter will croak or return undef,\ndepending on the setting of \"onerror\" in the constructor.\n\n$strptime->formatdatetime($datetime)\nGiven a \"DateTime\" object, this methods returns a string formatted in the object's format. This\nmethod is synonymous with \"DateTime\"'s strftime method.\n\n$strptime->locale\nThis method returns the locale passed to the object's constructor.\n\n$strptime->pattern\nThis method returns the pattern passed to the object's constructor.\n\n$strptime->timezone\nThis method returns the time zone passed to the object's constructor.\n\n$strptime->errmsg\nIf the onerror behavior of the object is 'undef', you can retrieve error messages with this\nmethod so you can work out why things went wrong.\n",
            "subsections": []
        },
        "EXPORTS": {
            "content": "These subs are available as optional exports.\n\nstrptime( $strptimepattern, $string )\nGiven a pattern and a string this function will return a new \"DateTime\" object.\n\nstrftime( $strftimepattern, $datetime )\nGiven a pattern and a \"DateTime\" object this function will return a formatted string.\n",
            "subsections": []
        },
        "STRPTIME PATTERN TOKENS": {
            "content": "The following tokens are allowed in the pattern string for strptime (parsedatetime):\n\n*   %%\n\nThe % character.\n\n*   %a or %A\n\nThe weekday name according to the given locale, in abbreviated form or the full name.\n\n*   %b or %B or %h\n\nThe month name according to the given locale, in abbreviated form or the full name.\n\n*   %c\n\nThe datetime format according to the given locale.\n\nNote that this format can change without warning in new versions of DateTime::Locale. You\nshould not use this pattern unless the string you are parsing was generated by using this\npattern with DateTime and you are sure that this string was generated with the same version\nof DateTime::Locale that the parser is using.\n\n*   %C\n\nThe century number (0-99).\n\n*   %d or %e\n\nThe day of month (01-31). This will parse single digit numbers as well.\n\n*   %D\n\nEquivalent to %m/%d/%y. (This is the American style date, very confusing to non-Americans,\nespecially since %d/%m/%y is widely used in Europe. The ISO 8601 standard pattern is %F.)\n\n*   %F\n\nEquivalent to %Y-%m-%d. (This is the ISO style date)\n\n*   %g\n\nThe year corresponding to the ISO week number, but without the century (0-99).\n\n*   %G\n\nThe 4-digit year corresponding to the ISO week number.\n\n*   %H\n\nThe hour (00-23). This will parse single digit numbers as well.\n\n*   %I\n\nThe hour on a 12-hour clock (1-12).\n\n*   %j\n\nThe day number in the year (1-366).\n\n*   %m\n\nThe month number (01-12). This will parse single digit numbers as well.\n\n*   %M\n\nThe minute (00-59). This will parse single digit numbers as well.\n\n*   %n\n\nArbitrary whitespace.\n\n*   %N\n\nNanoseconds. For other sub-second values use \"%[number]N\".\n\n*   %p or %P\n\nThe equivalent of AM or PM according to the locale in use. See DateTime::Locale.\n\n*   %r\n\nEquivalent to %I:%M:%S %p.\n\n*   %R\n\nEquivalent to %H:%M.\n\n*   %s\n\nNumber of seconds since the Epoch.\n\n*   %S\n\nThe second (0-60; 60 may occur for leap seconds. See DateTime::LeapSecond).\n\n*   %t\n\nArbitrary whitespace.\n\n*   %T\n\nEquivalent to %H:%M:%S.\n\n*   %U\n\nThe week number with Sunday the first day of the week (0-53). The first Sunday of January is\nthe first day of week 1.\n\n*   %u\n\nThe weekday number (1-7) with Monday = 1. This is the \"DateTime\" standard.\n\n*   %w\n\nThe weekday number (0-6) with Sunday = 0.\n\n*   %W\n\nThe week number with Monday the first day of the week (0-53). The first Monday of January is\nthe first day of week 1.\n\n*   %x\n\nThe date format according to the given locale.\n\nNote that this format can change without warning in new versions of DateTime::Locale. You\nshould not use this pattern unless the string you are parsing was generated by using this\npattern with DateTime and you are sure that this string was generated with the same version\nof DateTime::Locale that the parser is using.\n\n*   %X\n\nThe time format according to the given locale.\n\nNote that this format can change without warning in new versions of DateTime::Locale. You\nshould not use this pattern unless the string you are parsing was generated by using this\npattern with DateTime and you are sure that this string was generated with the same version\nof DateTime::Locale that the parser is using.\n\n*   %y\n\nThe year within century (0-99). When a century is not otherwise specified (with a value for\n%C), values in the range 69-99 refer to years in the twentieth century (1969-1999); values\nin the range 00-68 refer to years in the twenty-first century (2000-2068).\n\n*   %Y\n\nA 4-digit year, including century (for example, 1991).\n\n*   %z\n\nAn RFC-822/ISO 8601 standard time zone specification. (For example +1100) [See note below]\n\n*   %Z\n\nThe timezone name. (For example EST -- which is ambiguous) [See note below]\n\n*   %O\n\nThis extended token allows the use of Olson Time Zone names to appear in parsed strings.\nNOTE: This pattern cannot be passed to \"DateTime\"'s \"strftime()\" method, but can be passed\nto \"formatdatetime()\".\n",
            "subsections": []
        },
        "AUTHOR EMERITUS": {
            "content": "This module was created by Rick Measham.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "\"datetime@perl.org\" mailing list.\n\nhttp://datetime.perl.org/\n\nperl, DateTime, DateTime::TimeZone, DateTime::Locale\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Please report any bugs or feature requests to \"bug-datetime-format-strptime@rt.cpan.org\", or\nthrough the web interface at <http://rt.cpan.org>. I will be notified, and then you'll\nautomatically be notified of progress on your bug as I make changes.\n\nBugs may be submitted at <https://github.com/houseabsolute/DateTime-Format-Strptime/issues>.\n\nThere is a mailing list available for users of this distribution, <mailto:datetime@perl.org>.\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-Strptime can be found at\n<https://github.com/houseabsolute/DateTime-Format-Strptime>.\n",
            "subsections": []
        },
        "DONATIONS": {
            "content": "If you'd like to thank me for the work I've done on this module, please consider making a\n\"donation\" to me via PayPal. I spend a lot of free time creating free software, and would\nappreciate any support you'd care to offer.\n\nPlease note that I am not suggesting that you must do this in order for me to continue working\non this particular software. I will continue to do so, inasmuch as I have in the past, for as\nlong as it interests me.\n\nSimilarly, a donation made in this way will probably not make me work on this software much\nmore, unless I get so many donations that I can consider working on free software full time\n(let's all have a chuckle at that together).\n\nTo donate, log into PayPal and send money to autarch@urth.org, or use the button at\n<https://www.urth.org/fs-donation.html>.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "*   Dave Rolsky <autarch@urth.org>\n\n*   Rick Measham <rickm@cpan.org>\n",
            "subsections": []
        },
        "CONTRIBUTORS": {
            "content": "*   Christian Hansen <chansen@cpan.org>\n\n*   D. Ilmari Mannsåker <ilmari.mannsaker@net-a-porter.com>\n\n*   gregor herrmann <gregoa@debian.org>\n\n*   key-amb <yasutake.kiyoshi@gmail.com>\n\n*   Mohammad S Anwar <mohammad.anwar@yahoo.com>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is Copyright (c) 2015 - 2021 by Dave Rolsky.\n\nThis is free software, licensed under:\n\nThe Artistic License 2.0 (GPL Compatible)\n\nThe full text of the license can be found in the LICENSE file included with this distribution.\n",
            "subsections": []
        }
    },
    "summary": "DateTime::Format::Strptime - Parse and format strp and strf time patterns",
    "flags": [],
    "examples": [],
    "see_also": []
}