Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7910799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:00:24+00:00 2026-06-03T13:00:24+00:00

I have a date time string that I don’t know how to parse it

  • 0

I have a date time string that I don’t know how to parse it in Python.

The string is like this:

Tue May 08 15:14:45 +0800 2012

I tried

datetime.strptime("Tue May 08 15:14:45 +0800 2012","%a %b %d %H:%M:%S %z %Y")

but Python raises

'z' is a bad directive in format '%a %b %d %H:%M:%S %z %Y'

According to Python doc:

%z UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive).

What is the right format to parse this time string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:00:28+00:00Added an answer on June 3, 2026 at 1:00 pm

    datetime.datetime.strptime has problems with timezone parsing. Have a look at the dateutil package:

    >>> from dateutil import parser
    >>> parser.parse("Tue May 08 15:14:45 +0800 2012")
    datetime.datetime(2012, 5, 8, 15, 14, 45, tzinfo=tzoffset(None, 28800))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a service that give me a date time string in the following
I have a database script that returns date time string and my problem is
How can I parse a string that represents a date and/or time using iPhone
In Java 6, I have a date string that looks like 2011-11-28T21:00:00Z How would
I have a csv file where one of the columns is a date/time string.
I'm trying to make a Regex that matches this string {Date HH:MM:ss}, but here's
I have 2 areas that I know are process whores but I don't know
I don't know anything about regular expressions and I don't really have the time
I have a string representing date/time with timezone. I want to change the timezone
I have this object: class a { public string Application; public DateTime From, To;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.