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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:47:12+00:00 2026-05-13T21:47:12+00:00

How can I convert a date time string of the form Feb 25 2010,

  • 0

How can I convert a date time string of the form Feb 25 2010, 16:19:20 CET to the unix epoch?

Currently my best approach is to use time.strptime() is this:

def to_unixepoch(s):
    # ignore the time zone in strptime
    a = s.split()
    b = time.strptime(" ".join(a[:-1]) + " UTC", "%b %d %Y, %H:%M:%S %Z")
    # this puts the time_tuple(UTC+TZ) to unixepoch(UTC+TZ+LOCALTIME)
    c = int(time.mktime(b))
    # UTC+TZ
    c -= time.timezone
    # UTC
    c -= {"CET": 3600, "CEST": 2 * 3600}[a[-1]]
    return c

I see from other questions that it might be possible to use calendar.timegm(), and pytz among others to simplify this, but these don’t handle the abbreviated time zones.

I’d like a solution that requires minimal excess libraries, I like to keep to the standard library as much as possible.

  • 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-13T21:47:13+00:00Added an answer on May 13, 2026 at 9:47 pm

    The Python standard library does not really implement time zones. You should use python-dateutil. It provides useful extensions to the standard datetime module including a time zones implementation and a parser.

    You can convert time zone aware datetime objects to UTC with .astimezone(dateutil.tz.tzutc()). For the current time as a timezone aware datetime object, you can use datetime.datetime.utcnow().replace(tzinfo=dateutil.tz.tzutc()).

    import dateutil.tz
    
    cet = dateutil.tz.gettz('CET')
    
    cesttime = datetime.datetime(2010, 4, 1, 12, 57, tzinfo=cet)
    cesttime.isoformat()
    '2010-04-01T12:57:00+02:00'
    
    cettime = datetime.datetime(2010, 1, 1, 12, 57, tzinfo=cet)
    cettime.isoformat() 
    '2010-01-01T12:57:00+01:00'
    
    # does not automatically parse the time zone portion
    dateutil.parser.parse('Feb 25 2010, 16:19:20 CET')\
        .replace(tzinfo=dateutil.tz.gettz('CET'))
    

    Unfortunately this technique will be wrong during the repeated daylight savings time hour.

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

Sidebar

Related Questions

To convert a date from string to Unix time, I can use date --date
How can I convert UTC date-time string (e.g. 2011-03-29 17:06:21 UTC ) into Epoch
How can I convert a string to a date time object in javascript by
Can anyone suggest an easy method to convert date and time to different timezones
I have a date/time string like 2012-01-13 04:37:20 but I want to convert it
This line System.DateTime.Parse(09/12/2009); convert date (string) to 9/12/2009 12:00:00 AM. How can I get
I want to convert the time stamp (epoch time) to human readable string. For
Possible Duplicate: how to convert java string to Date object I have a form
How can I convert this string date to datetime in oracle. 2011-07-28T23:54:14Z Using this
I'm trying to convert a parameter of type string to a date time. I'm

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.