I need to convert UTC time, (on ec2 instance) to PST. I am trying to do this.
from datetime import datetime
from pytz import timezone
import pytz
date_format='%m/%d/%Y %H:%M:%S %Z'
date = datetime.now()
print 'Current date & time is:', date.strftime(date_format)
my_timezone=timezone('US/Pacific')
date = my_timezone.localize(date)
date = date.astimezone(my_timezone)
print 'Local date & time is :', date.strftime(date_format)
But the output is:
Current date & time is: 01/10/2012 20:01:14
Local date & time is : 01/10/2012 20:01:14 PST
Any reason why I am not getting the right PST time?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…