I recommend using python-dateutil. Its parser has been able to parse every date format I've thrown at it so far.

>>> from dateutil import parser
>>> parser.parse("Tue Jun 22 07:46:22 EST 2010")
datetime.datetime(2010, 6, 22, 7, 46, 22, tzinfo=tzlocal())
>>> parser.parse("Fri, 11 Nov 2011 03:18:09 -0400")
datetime.datetime(2011, 11, 11, 3, 18, 9, tzinfo=tzoffset(None, -14400))
>>> parser.parse("Sun")
datetime.datetime(2011, 12, 18, 0, 0)
>>> parser.parse("10-11-08")
datetime.datetime(2008, 10, 11, 0, 0)

and so on. No dealing with strptime() format nonsense... just throw a date at it and it Does The Right Thing.

Answer from Joe Shaw on Stack Overflow
Discussions

`Time::Piece` and `strptime()` processing timezones documentation discrepancy
Delimiter in timezone offset isn’t permitted for %z. More on reddit.com
🌐 r/perl
9
10
January 1, 2022
%Z in strptime doesn't match EST and others
BPO 22377 Nosy @abalkin, @bitdancer, @karlcow, @4kir4, @berkerpeksag, @pganssle, @miss-islington, @kkirsche PRs #16507 Files draft-strptime-%Z-timezones.diff Note: these values reflect the state of the issue at the time it was migrated a... More on github.com
🌐 github.com
24
September 9, 2014
People also ask

How to use strptime() parsing a datetime string with a timezone offset?
Include the %z format specifier to correctly interpret timezone offsets.
🌐
intellipaat.com
intellipaat.com › home › blog › convert timestamps with offset to datetime obj using strptime
Convert timestamps with offset to datetime obj using strptime - ...
Is it possible to use the strptime() to handle the UTC or named time zones (e.g., EST, PST)?
No, the strptime() supports numeric timezone offsets (e.g., +0530) only. Handling the named time zones can be achieved by using the libraries like pytz or zoneinfo.
🌐
intellipaat.com
intellipaat.com › home › blog › convert timestamps with offset to datetime obj using strptime
Convert timestamps with offset to datetime obj using strptime - ...
How to use the strptime() function in Python?
strptime() is a function in Python’s datetime module that parses a date-time string into a datetime object based on a specified format.
🌐
intellipaat.com
intellipaat.com › home › blog › convert timestamps with offset to datetime obj using strptime
Convert timestamps with offset to datetime obj using strptime - ...
🌐
Python documentation
docs.python.org › 3 › library › datetime.html
datetime — Basic date and time types
Same as datetime.strftime(). This ... datetime.now() >>> dt.datetime.now() datetime.datetime(2007, 12, 6, 16, 29, 43, 79043) # GMT +1 >>> dt.datetime.now(dt.timezone.utc) datetime.datetime(2007, 12, 6, 15, 29, 43,...
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-string-to-datetime-in-python-with-timezone
Convert string to datetime in Python with timezone - GeeksforGeeks
July 23, 2025 - Explanation: string s is parsed into a datetime object using datetime.strptime(), which requires an exact format string ('%Y-%m-%d %H:%M:%S.%f %z') to correctly interpret each component of the date, time and timezone.
🌐
APIdock
apidock.com › rails › v5.2.3 › ActiveSupport › TimeZone › strptime
strptime (ActiveSupport::TimeZone) - APIdock
Time.zone = 'Hawaii' # => "Hawaii" Time.zone.strptime('1999-12-31 14:00:00', '%Y-%m-%d %H:%M:%S') # => Fri, 31 Dec 1999 14:00:00 HST -10:00 · If upper components are missing from the string, they are supplied from TimeZone#now: Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00 Time.zone.strptime('22:30:00', '%H:%M:%S') # => Fri, 31 Dec 1999 22:30:00 HST -10:00 ·
🌐
Reddit
reddit.com › r/perl › `time::piece` and `strptime()` processing timezones documentation discrepancy
r/perl on Reddit: `Time::Piece` and `strptime()` processing timezones documentation discrepancy
January 1, 2022 -

My log files have the date/time formatted as: 2022-01-01T11:53:42-08:00. I need to convert that to a Unixtime. I think strptime() is the easiest way to do this?

Here is the code I came up with to process this specific time string.

#!/usr/bin/env perl

use strict;
use warnings;
use Time::Piece;

my $input = '2022-01-01T11:53:42-08:00';
my $tp     = Time::Piece->strptime($input, "%Y-%m-%dT%H:%M:%S");

print "Input : $input\n";
print "Epoch : " . $tp->epoch . "\n";
print "Format: " . $tp->cdate . "\n";

When I run this I get an error about the timezone string at the end

Garbage at end of string in strptime: -08:00 at /usr/lib64/perl5/Time/Piece.pm line 598.
Perhaps a format flag did not match the actual input? at /usr/lib64/perl5/Time/Piece.pm line 598.

The documentation says to add %z to process timezones, but when I do that it fails completely. How do I make strptime() process this string correctly? Is there a better/easier way to convert this?

🌐
Cheat Sheets
cheat.readthedocs.io › en › latest › python › timezones.html
Timezones in Python — Dan's Cheat Sheets 1 documentation
>>> fmt = "%a, %d %B %Y %H:%M:%S" >>> dt = datetime.datetime.strptime(s[:-6], fmt) >>> dt datetime.datetime(2012, 7, 3, 14, 11, 3) That is assuming we know exactly how long the timezone string was, but we might not.
Find elsewhere
🌐
Splunk Community
community.splunk.com › t5 › Getting-Data-In › Time-zone-in-TIME-FORMAT › m-p › 52193
Solved: Time zone in TIME_FORMAT - Splunk Community
February 23, 2020 - | makeresults | eval time1="01/Mar/2011:17:25:49.666+0000" | appendpipe [ eval time2="2015-10-22T22:41:52.546249+00:00"] | eval _time=coalesce(strptime(time2,"%FT%T.%6Q%:z"),strptime(time1,"%d/%B/%Y:%T.%3Q%z")) ... Rather than submitting yet another question about timestamp formating, could you please update your answer with the correct format string to successfully parse a timestamp like 2015-10-22T22:41:52.546249+00:00? I tried %Y-%m-%dT%H:%M:%S.%6N%:z, but it doesn't seems to be working. The timezone info is probably not being captured as all event times are being translated as if the event timezone (always UTC) was the same as the splunk server (-0500), which, translated to my splunk user timezone (-0200), gives me 2015-10-23T01:41:52.546249-02:00.
🌐
GitHub
github.com › python › cpython › issues › 66571
%Z in strptime doesn't match EST and others · Issue #66571 · python/cpython
September 9, 2014 - assignee = None closed_at = None created_at = <Date 2014-09-09.22:24:15.542> labels = ['3.7', '3.8', 'type-bug', 'library', '3.9'] title = "%Z in strptime doesn't match EST and others" updated_at = <Date 2021-11-01.12:58:19.684> user = 'https://github.com/cool-RR'
Author   cool-RR
🌐
Astral
docs.astral.sh › ruff › rules › call-datetime-strptime-without-zone
call-datetime-strptime-without-zone (DTZ007) | Ruff
Since this can lead to errors, it is recommended to always use timezone-aware objects. datetime.datetime.strptime() without %z returns a naive datetime object.
🌐
Python Forum
python-forum.io › thread-42051.html
Convert UTC now() to local time to compare to a strptime()
I have a string that contains a local time "2024-12-31 23:59:59". The local time is "America/Edmonton". The time zone on my machine is UTC, so datetime.now() returns UTC time. if the current time is l
🌐
GitHub
gist.github.com › pglezen › 233c2228e65655938e53c0037c4de029
Parsing timestamps with Z in Python · GitHub
Parsing timestamps with Z in Python. GitHub Gist: instantly share code, notes, and snippets.
🌐
R Package
rdrr.io › r › base › strptime.html
strptime: Date-time Conversion Functions to and from Character
Remember that in most time zones some times do not occur and some occur twice because of transitions to/from ‘daylight saving’ (also known as ‘summer’) time. strptime does not validate such times (it does not assume a specific time zone), but conversion by as.POSIXct will do so.
🌐
Python
bugs.python.org › issue22377
Issue 22377: %Z in strptime doesn't match EST and others - Python tracker
September 9, 2014 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/66571
🌐
Medium
medium.com › @eleroy › 10-things-you-need-to-know-about-date-and-time-in-python-with-datetime-pytz-dateutil-timedelta-309bfbafb3f7
10 things you need to know about Date and Time in Python with datetime, pytz, dateutil & timedelta | by Emmanuel | Medium
October 8, 2023 - Now, sometimes you need to deal with naive dates, which means you need to know the timezone in order to do anything useful with them, like convert to a timestamp. Converting a date to a UTC timestamp, as mentioned above, take a little more effort to make sure the date is in UTC to begin with: # naive datetime d = datetime.datetime.strptime('01/12/2011', '%d/%m/%Y') >>> datetime.datetime(2011, 12, 1, 0, 0)# timestamp will convert the localized naive datetime into a unix timestamp d.timestamp() >>> 1322726400.0
🌐
MetaCPAN
metacpan.org › pod › DateTime::Format::Strptime
DateTime::Format::Strptime - Parse and format strp and strf time patterns - metacpan.org
The timezone name. (For example EST -- which is ambiguous) [See note below] ... This extended token allows the use of Olson Time Zone names to appear in parsed strings. NOTE: This pattern cannot be passed to DateTime's strftime() method, but ...
🌐
Analytics Vidhya
analyticsvidhya.com › home › python datetime – strptime() function
Python DateTime - strptime() Function - Analytics Vidhya
May 23, 2025 - `%Z` – Timezone: This directive represents the timezone. For example, `%Z` will parse the timezone as ‘UTC’ or ‘GMT’. Suppose we have a string representation of a date and time: ‘2022-01-01 13:30:45’. We can use the `strptime()` ...
🌐
Intellipaat
intellipaat.com › home › blog › convert timestamps with offset to datetime obj using strptime
Convert timestamps with offset to datetime obj using strptime - Intellipaat
February 2, 2026 - This blog will explain how to convert the timestamps with offset to datetime object using strptime() function. ... To parse a datetime string having the timezone offset in Python, the strptime() Function can be used.