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

  • SEARCH
  • Home
  • 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 8304133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:45:33+00:00 2026-06-08T17:45:33+00:00

I have to deal in python with strings representing iso8601 timestamps. My timestamps string

  • 0

I have to deal in python with strings representing iso8601 timestamps.

My timestamps string are therefore in the following form:

timestamp = "2011-08-18T10:29:47+03:00"

Currently I’m converting them in python using:

timestamp = timestamp[:-6]
timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S")

But in this way I lose all the information about the time zone.
I have seen many examples here on s-o about timestamps and python, unfortunately no one was preserving the timezone as well, or just recover the time zone delay using:

delay = timestamp[-6:]

I have also tried:

timestamp = "2011-08-18T10:29:47+03:00"
timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S%z")

but it returned

ValueError: 'z' is a bad directive in format '%Y-%m-%dT%H:%M:%S%z'

Can you give some insight?

  • 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-08T17:45:36+00:00Added an answer on June 8, 2026 at 5:45 pm

    The python iso8601 module is built with a wonderful parse_date method that can handle timezone info :

    >>> import iso8601
    >>> iso8601.parse_date("2007-01-25T12:00:00Z")
    datetime.datetime(2007, 1, 25, 12, 0, tzinfo=<iso8601.iso8601.Utc ...>)
    
    >>> iso8601.parse_date("2011-08-18T10:29:47+03:00")
    datetime.datetime(2011, 8, 18, 10, 29, 47, tzinfo=<FixedOffset '+03:00'>)
    

    If you want to convert it in another timezone, use the astimezone(tz) method

    If you need to get the UTC datetime you can use the utctimetuple() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in a rails project i have to deal with lots of strings, that are
Possible Duplicate: Can Super deal with multiple inheritance? Python inheritance? I have a class
I have the following need (in python): generate all possible tuples of length 12
I have a python client which pushes a great deal of data through the
Here's the deal. Is there a way to have strings tokenized in a line
I am on google app engine with Python 2.5. My application have to deal
I'm currently rewriting some python code to make it more efficient and I have
I have to deal with an API which need to be provided a DataSource
I have a deal with a 3rd party web page. And If I click
I do have to deal with very large plain text files (over 10 gigabytes,

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.