man > DateTime::Format::Strptime

πŸ“˜ NAME

DateTime::Format::Strptime – Parse and format strp and strf time patterns

πŸš€ Quick Reference

Use CaseCommandDescription
πŸ“… Parse a date stringmy $dt = $strp->parse_datetime('23:16:42');Use a DateTime::Format::Strptime object with a pattern to parse a string into a DateTime object.
πŸ“ Format a DateTime$strp->format_datetime($dt);Format a DateTime object back to a string using the same pattern.
⚠️ Handle errors gracefullyon_error => 'croak' or on_error => \&subControl error behaviour: return undef, croak, or call a custom subroutine.
πŸ”’ Strict parsingstrict => 1Force the pattern to match only at word boundaries, avoiding unexpected substring matches.

πŸ“¦ VERSION

version 1.79

πŸ“‹ SYNOPSIS

use DateTime::Format::Strptime;

my $strp = DateTime::Format::Strptime->new(
    pattern   => '%T',
    locale    => 'en_AU',
    time_zone => 'Australia/Melbourne',
);

my $dt = $strp->parse_datetime('23:16:42');

$strp->format_datetime($dt);

# 23:16:42

# Croak when things go wrong:
my $strp = DateTime::Format::Strptime->new(
    pattern   => '%T',
    locale    => 'en_AU',
    time_zone => 'Australia/Melbourne',
     'croak',
);

# Do something else when things go wrong:
my $strp = DateTime::Format::Strptime->new(
    pattern   => '%T',
    locale    => 'en_AU',
    time_zone => 'Australia/Melbourne',
     \&phone_police,
);

πŸ“– DESCRIPTION

This module implements most of strptime(3), the POSIX function that is the reverse of strftime(3), for "DateTime". While "strftime" takes a "DateTime" and a pattern and returns a string, "strptime" takes a string and a pattern and returns the "DateTime" object associated.

βš™οΈ METHODS

This class offers the following methods.

πŸ”§ DateTime::Format::Strptime->new(%args)

This methods creates a new object. It accepts the following arguments:

πŸ”§ $strptime->parse_datetime($string)

Given a string in the pattern specified in the constructor, this method will return a new DateTime object.

If given a string that doesn't match the pattern, the formatter will croak or return undef, depending on the setting of on_error in the constructor.

πŸ”§ $strptime->format_datetime($datetime)

Given a DateTime object, this methods returns a string formatted in the object's format. This method is synonymous with DateTime's strftime method.

πŸ”§ $strptime->locale

This method returns the locale passed to the object's constructor.

πŸ”§ $strptime->pattern

This method returns the pattern passed to the object's constructor.

πŸ”§ $strptime->time_zone

This method returns the time zone passed to the object's constructor.

πŸ”§ $strptime->errmsg

If the on_error behavior of the object is 'undef', you can retrieve error messages with this method so you can work out why things went wrong.

πŸ“¦ EXPORTS

These subs are available as optional exports.

πŸ“€ strptime( $strptime_pattern, $string )

Given a pattern and a string this function will return a new DateTime object.

πŸ“€ strftime( $strftime_pattern, $datetime )

Given a pattern and a DateTime object this function will return a formatted string.

πŸ”€ STRPTIME PATTERN TOKENS

The following tokens are allowed in the pattern string for strptime (parse_datetime):

πŸ‘€ AUTHOR EMERITUS

This module was created by Rick Measham.

πŸ“š SEE ALSO

"datetime AT perl.org" mailing list.

http://datetime.perl.org/

perl, DateTime, DateTime::TimeZone, DateTime::Locale

πŸ› BUGS

Please report any bugs or feature requests to "bug-datetime-format-strptime AT rt.org", or through the web interface at <http://rt.cpan.org>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

Bugs may be submitted at <https://github.com/houseabsolute/DateTime-Format-Strptime/issues>.

There is a mailing list available for users of this distribution, <mailto:datetime AT perl.org>.

I am also usually active on IRC as 'autarch' on "irc://irc.perl.org".

πŸ“œ SOURCE

The source code repository for DateTime-Format-Strptime can be found at <https://github.com/houseabsolute/DateTime-Format-Strptime>.

πŸ’° DONATIONS

If you'd like to thank me for the work I've done on this module, please consider making a "donation" to me via PayPal. I spend a lot of free time creating free software, and would appreciate any support you'd care to offer.

Please note that I am not suggesting that you must do this in order for me to continue working on this particular software. I will continue to do so, inasmuch as I have in the past, for as long as it interests me.

Similarly, a donation made in this way will probably not make me work on this software much more, unless I get so many donations that I can consider working on free software full time (let's all have a chuckle at that together).

To donate, log into PayPal and send money to autarch AT urth.org, or use the button at <https://www.urth.org/fs-donation.html>.

πŸ‘₯ AUTHORS

🀝 CONTRIBUTORS

πŸ“„ COPYRIGHT AND LICENSE

This software is Copyright (c) 2015 - 2021 by Dave Rolsky.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

The full text of the license can be found in the LICENSE file included with this distribution.


perl v5.32.1 – 2021-08-22 – DateTime::Format::Strptime(3pm)

DateTime::Format::Strptime
πŸ“˜ NAME πŸš€ Quick Reference πŸ“¦ VERSION πŸ“‹ SYNOPSIS πŸ“– DESCRIPTION βš™οΈ METHODS
πŸ”§ DateTime::Format::Strptime->new(%args) πŸ”§ $strptime->parse_datetime($string) πŸ”§ $strptime->format_datetime($datetime) πŸ”§ $strptime->locale πŸ”§ $strptime->pattern πŸ”§ $strptime->time_zone πŸ”§ $strptime->errmsg
πŸ“¦ EXPORTS
πŸ“€ strptime( $strptime_pattern, $string ) πŸ“€ strftime( $strftime_pattern, $datetime )
πŸ”€ STRPTIME PATTERN TOKENS πŸ‘€ AUTHOR EMERITUS πŸ“š SEE ALSO πŸ› BUGS πŸ“œ SOURCE πŸ’° DONATIONS πŸ‘₯ AUTHORS 🀝 CONTRIBUTORS πŸ“„ COPYRIGHT AND LICENSE

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-05 12:24 @216.73.216.89
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^