need to convert UTC (aws ec2) to PST in python

前端 未结 5 1019
星月不相逢
星月不相逢 2020-12-08 15:58

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_form         


        
5条回答
  •  青春惊慌失措
    2020-12-08 16:24

    from datetime import datetime
    from pytz import timezone
    import pytz
    
    date_format='%m/%d/%Y %H:%M:%S %Z'
    date = datetime.now(tz=pytz.utc)
    print 'Current date & time is:', date.strftime(date_format)
    
    date = date.astimezone(timezone('US/Pacific'))
    
    print 'Local date & time is  :', date.strftime(date_format)
    

    seems to work for me :) - timezones are confusing, slowly making a plan of what I actually want to do helps me most of the time

提交回复
热议问题