By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 1,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

strptime() doesn't recognize BST as a valid timezone

P: n/a
I'm unable to parse the following date string using time.strptime():
"Wed Sep 14, 2005 5:07 PM BST"

Format: "%a %b %d, %Y %I:%M %p %Z"

I tried changing the locale and using time.tzset(), but no luck. Is
there anyone in London (or some other BST location) that would try
running the following code?

import time
date_str = "Wed Sep 14, 2005 5:07 PM BST"
format = "%a %b %d, %Y %I:%M %p %Z"
time.strptime(date_str, format)

I get: "ValueError: time data did not match format: ..."

NOTE: there is a workable solution to getting this date into the proper
timezone ('Europe/London'), but I'm still unable to parse the 'BST'
part, even after setting the locale to en_GB.utf8 and the timezone to
'Europe/London'. Here's a solution to "zoning" naive date strings: (full url:

I did notice that the Python docs mention %Z is deprecated, so is possibly the best solution available for


Adam Monsen

Sep 14 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Ok, I've figured this out.
import os, time
date = '10 August 2005 at 17:26 BST'
format = '%d %B %Y at %H:%M %Z'
os.environ['TZ'] = 'Europe/London'
time.strptime(date, format)

(2005, 8, 10, 17, 26, 0, 2, 222, 1)

Works (unsuprisingly) as advertised at the bottom of this page:

And now I'm a little closer to understanding why. :)

Adam Monsen

Sep 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.