2016-11-24 23 views
0

Ich mag datetime.datetime(2016, 11, 21, 5, 34, 38, 826339, tzinfo=<UTC>) als Nov. 21, 2016, 11:04 a.m.Änderung Datetime-Objekt Zeichenfolge

Die Zeit in dem Datetime-Objekt konvertieren ist in UST aber ich will es in IST (UST + 5.30) umgewandelt werden.

Ich versuchte Strftime wie mit: hier

>>> datetime(2016, 11, 21, 5, 34, 38, 826339, tzinfo=<UTC>).isoformat(' ') 
    File "<stdin>", line 1 
    datetime(2016, 11, 21, 5, 34, 38, 826339, tzinfo=<UTC>).isoformat(' ') 
                ^
SyntaxError: invalid syntax 

Kann ich etwas Hilfe bekommen.

PS: Ich verwende Python

EDIT:

cr_date = datetime(2016, 11, 21, 5, 34, 38, 826339) #excluding the timezone 

ich teilweise gewünschte reults durch bekommen:

cr_date.strftime('%b. %d, %Y %H:%M') 
'Oct. 31, 2013 18:23 

hatte nicht den am/pm obwohl

Antwort

0

Für den am/pm Teil, konnte nicht% p für das letzte Feld verwendet werden? Ich weiß nicht, Python, ich nehme nur an, Python nimmt Syntax aus dem Unix-Datum Befehl.

0

%p hinzufügen für 'AM oder PM' sonst hinzufügen %P für 'am oder pm'

0

finden Sie unter Code

from datetime import datetime 
cr_date = datetime(2016, 11, 21, 5, 34, 38, 826339) 
cr_date.strftime('%b. %d, %Y %H:%M %P') 
'Nov. 21, 2016 05:34 am'