Convert datetime to local python

I have been reading quite some time answers and couldn't really drive into results.

I have the following code:

>>>from datetime import datetime
>>>a = '2013-08-23T23:37:38+0000'
>>>dt = datetime.strptime(a,'%Y-%m-%dT%H:%M:%S+0000')
>>>print   dt.date()
2013-08-23
>>>print   dt.time()
23:37:38

What is the simplest way to output this result (assuming of course that a is unknown) given that we live in Central Europe. So it should be "daylight saving-proof" as well.

In winter:

2013-08-24
00:37:38

In summer:

2013-08-24
01:37:38

If it only needs default libraries it would be great.


Some more info

I dived into the libraries after my question. My above 3rd line should be better be: dt = datetime.strptime(a,'%Y-%m-%dT%H:%M:%S%z'). However a bug came out in 2.7.5 python (OS X if it matters) and had some trouble finding the %z. If you have trouble change version, if not ignore this. Of course the strptime() is just simpler level of dateutil.parser mentioned in the two answers so it can better be used instead of my code above.

Answers


you can use the useful dateutil package and the pytz one for exemple convert to paris timezone

from dateutil import parser
import pytz
FR = pytz.timezone('Europe/Paris') # there is the summer offset changing in this zone
date = parser.parse("2013-08-23T23:37:38+0000")
datefr = date.astimezone(FR)

Here's an example using pytz and dateutil:

from dateutil import parser
import pytz


date = parser.parse('2013-08-23T23:37:38+0000')

CET = pytz.timezone('CET')
date = date.astimezone(CET)

print date.date()  # prints 2013-08-24
print date.time()  # prints 01:37:38

Need Your Help

How can I encrypt/decrypt data using AES CBC+CTS (ciphertext stealing) mode in PHP?

php .net cryptography aes mcrypt

I have to encrypt and decrypt data in AES CTS mode (ciphertext stealing, sometimes referred as AES-XTS) in PHP to interoperate with a remote system written in .NET platform. In .NET 4, this mode is

How can I fade in a JPanel & children?

java swing awt jpanel fadein

I know that I can fade in a panel, by adding the alpha value to the background color & a timer. But how can I fade in a panel with child components (like a JLabel)?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.