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 6110667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:32:30+00:00 2026-05-23T14:32:30+00:00

I understand how to convert a string to a datetime object, but what about

  • 0

I understand how to convert a string to a datetime object, but what about a string that has a different time zone? for example “10/07/2011 04:22 CEST”

  • 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-05-23T14:32:31+00:00Added an answer on May 23, 2026 at 2:32 pm

    EST can mean two different timezones: European Summer Time, or Eastern Standard Time. So datetime strings such as 08/07/2011 04:22 EST are ambiguous — there’s no sure-fire way to correctly convert such strings to a timezone-aware datetime.

    If you are willing to just make a stab at a possibly correct answer, then
    you can generate a mapping between abbreviations like EST and timezone names, make a random choice among the valid timezones, and
    then use that timezone to build a timezone-aware datetime:

    import dateutil.tz as dtz
    import pytz
    import datetime as dt
    import collections
    import random
    
    timezones = collections.defaultdict(list)
    for name in pytz.common_timezones:
        timezone = dtz.gettz(name)
        try:
            now = dt.datetime.now(timezone)
        except ValueError:
            # dt.datetime.now(dtz.gettz('Pacific/Apia')) raises ValueError
            continue
        abbrev = now.strftime('%Z')
        timezones[abbrev].append(name) 
    
    date_string, tz_string = '10/07/2011 04:22 CEST'.rsplit(' ', 1)
    date = dt.datetime.strptime(date_string, '%m/%d/%Y %H:%M')
    print(date)
    # 2011-10-07 04:22:00
    
    tz = pytz.timezone(random.choice(timezones[tz_string]))
    print(tz)
    # Europe/Oslo
    
    date = tz.localize(date)
    print(date)
    # 2011-10-07 04:22:00+02:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datetime string in non-English locale and Time.parse doesn't understand it: Pr,
I am looking to convert pixes to inches and vice versa. I understand that
I want know the passed time that also is between two date, for example
I'm using an api that returns the date as a string, like so: 2011-06-13T21:15:19Z
I want to convert my date (which is in String format), e.g. 13-09-2011, into
I have been using :_* to convert Seq[String] to String* and I realized that
How do I convert public key generated by OpenSSL into one NSS would understand?
I don't understand why 'x' below converts, but 'y' and 'z' do not. var
I understand what System.WeakReference does, but what I can't seem to grasp is a
I understand that some countries have laws regarding website accessibility. In general, what are

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.