Python Forum
time zone converting with list slicing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
time zone converting with list slicing
#5
something like this
from datetime import datetime
import pytz

def lon2swe(date_time):
    london_datetime_tzunaware = datetime.strptime(' '.join(date_time), '%Y-%m-%d %H%M%S.%f')
    london_datetime = london_datetime_tzunaware.replace(tzinfo = pytz.timezone('Europe/London'))
    swedish_datetime = london_datetime.astimezone(pytz.timezone('Europe/Stockholm'))
    return swedish_datetime
 
print(lon2swe(['2016-01-16', '17:22:10.171150']))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: time zone converting with list slicing - by buran - May-22-2018, 11:49 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020