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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:12:33+00:00 2026-06-11T21:12:33+00:00

Possible Duplicate: How to print date in a regular format in Python? I would

  • 0

Possible Duplicate:
How to print date in a regular format in Python?

I would like to know how to convert the following date to natural language, including time zone in python?

input:

"'2012-09-27T02:00:00Z'"

expected output:

Wednesday, September 26 of 2012 Mountain Time

Thanks in advance!

Note Edit:
So far I tried django humanize, although it doesn’t handle very well complex date-time strings.

Solution:

Thanks for all the information. I ended up parsing the original string and using pitz and strftime like this:

    my_date = '2012-09-27T02:00:00Z'
    utc_date_object = datetime(int(my_date[0:4]), int(my_date[5:7]), int(my_date[8:10]),int(my_date[11:13]),int(my_date[14:16]),int(my_date[17:19]),0,pytz.utc)
    mt_date_object = utc_date_object.replace(tzinfo=pytz.utc).astimezone(pytz.timezone('US/Mountain'))
    natural_date = mt_date_object.strftime("%A, %B %d of %Y")

Output:

'Wednesday, September 26 of 2012'
  • 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-11T21:12:34+00:00Added an answer on June 11, 2026 at 9:12 pm

    The Babel project offers a full-featured date and time localization library.

    You’ll also need the iso8601 module to parse a date-time string with a timezone correctly.

    It either formats dates and times based on locale:

    >>> from datetime import date, datetime, time
    >>> from babel.dates import format_date, format_datetime, format_time
    >>> d = date(2007, 4, 1)
    >>> format_date(d, locale='en')
    u'Apr 1, 2007'
    >>> format_date(d, locale='de_DE')
    u'01.04.2007'
    

    or it let’s you specify the format in detail. This includes formatting the timezone.

    Putting the parser and the formatter together:

    >>> dt = iso8601.parse_date("2012-08-25T02:00:00Z")
    >>> format_date(dt, "MMMM dd, yyyy", locale='en') + ' at ' + format_time(dt, "HH:mm V")
    u'August 25, 2012 at 02:00 World (GMT) Time'
    

    Ordinals (‘1st’, ‘2nd’, etc.) are a little harder to do internationally, and the LDML format used by Babel doesn’t include a pattern for these.

    If you must have an ordinal in your date formatting (perhaps because you only expect to output in English), you’ll have to create those yourself:

    >>> suffix = ('st' if dt.day in [1,21,31]
    ...                else 'nd' if dt.day in [2, 22] 
    ...                else 'rd' if dt.day in [3, 23]
    ...                else 'th')
    >>> u'{date}{suffix}, {year} at {time}'.format(
    ...     date=format_date(dt, "MMMM dd", locale='en'),
    ...     suffix=suffix, year=dt.year,
    ...     time=format_time(dt, "HH:mm V"))
    u'August 25th, 2012 at 02:00 World (GMT) Time'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Python, Printing multiple times, I'd like to know how to print a
Possible Duplicate: Correct format specifier to print pointer (address)? When printing a pointer using
Possible Duplicate: Python Ternary Operator If Python would support the (x ? a :
Possible Duplicate: Something like print END << END; in C++? In a shell script
Possible Duplicate: Can Python print a function definition? In Javascript, it is possible to
Possible Duplicate: Print in terminal with colors using python? Just curious So I want
Possible Duplicate: how to print number with commas as thousands separators in Python 2.x
Possible Duplicate: How should I print types like off_t and size_t? I'm using fstat(stream,
Possible Duplicate: Is there a printf converter to print in binary format? Consider this
Possible Duplicate: Is there a printf converter to print in binary format? Still learning

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.