views:

54

answers:

2

Hello,

How to get formatted date time in Python the same way as in PHP date('M d Y', $timestamp);?

+4  A: 

You can use a suitable strftime function. Here is an example using datetime objects.

>>> from datetime import datetime
>>> today = datetime.today()
>>> today.strftime("%m %d %Y")
'09 13 2010'
Manoj Govindan
Great, thanks! And how to get the same result from time formatted like 1284375159?
sultan
+5  A: 
>>> import time
>>> timestamp = 1284375159
>>> time.strftime("%m %d %Y",time.localtime(timestamp))
'09 13 2010'
gnibbler