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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:04:24+00:00 2026-05-30T16:04:24+00:00

I have a system (developed in Python) that accepts datetime as string in VARIOUS

  • 0

I have a system (developed in Python) that accepts datetime as string in VARIOUS formats and i have to parse them..Currently datetime string formats are :

Fri Sep 25 18:09:49 -0500 2009

2008-06-29T00:42:18.000Z

2011-07-16T21:46:39Z

1294989360

Now i want a generic parser that can convert any of these datetime formats in appropriate datetime object…

Otherwise, i have to go with parsing them individually. So please also provide method for parsing them individually (if there is no generic parser)..!!

  • 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-30T16:04:25+00:00Added an answer on May 30, 2026 at 4:04 pm

    As @TimPietzcker suggested, the dateutil package is the way to go, it handles the first 3 formats correctly and automatically:

    >>> from dateutil.parser import parse
    >>> parse("Fri Sep 25 18:09:49 -0500 2009")
    datetime.datetime(2009, 9, 25, 18, 9, 49, tzinfo=tzoffset(None, -18000))
    >>> parse("2008-06-29T00:42:18.000Z")
    datetime.datetime(2008, 6, 29, 0, 42, 18, tzinfo=tzutc())
    >>> parse("2011-07-16T21:46:39Z")
    datetime.datetime(2011, 7, 16, 21, 46, 39, tzinfo=tzutc())
    

    The unixtime format it seems to hiccough on, but luckily the standard datetime.datetime is up for the task:

    >>> from datetime import datetime
    >>> datetime.utcfromtimestamp(float("1294989360"))
    datetime.datetime(2011, 1, 14, 7, 16)
    

    It is rather easy to make a function out of this that handles all 4 formats:

    from dateutil.parser import parse
    from datetime import datetime
    
    def parse_time(s):
        try:
            ret = parse(s)
        except ValueError:
            ret = datetime.utcfromtimestamp(s)
        return ret
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a webservice into my companies self developed CRM system that we
I have a VB6 COM DLL that was developed on a WinXP 32bit system.
I currently have a local python application that scans a users drive, maps it
In a Python system for which I develop, we usually have this module structure.
The company I work for we have a CBT system we have developed. We
I have developed a build system on MSBuild (NET 3.0) and cc.net to perform
I have developed a small download system in PHP, where files are downloaded through
i have developed a web servcies in my local system with name (inbox service).
We have system here that uses Java JNI to call a function in a
Most python frameworks will have a development webserver of some kind that will have

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.