May-22-2019, 11:18 AM
I am working on the same homework but different task, so I wasn't sure if I had to start a new thread or not.
I think I am running into a logical error.
I am trying to convert the dates from UTC to Central european time.
The following code runs smoothly but the last 2 lines should print different results,
given the time difference, but the printed result is exactly the same.
How come?
I think I am running into a logical error.
I am trying to convert the dates from UTC to Central european time.
The following code runs smoothly but the last 2 lines should print different results,
given the time difference, but the printed result is exactly the same.
How come?
from astral import Astral from scipy import * from pylab import* import numpy as np from numpy import array import matplotlib.pyplot as plt import datetime from datetime import timezone import pandas as pd import pytz file=open('bird_jan25jan16.txt','r') #Turning datas in file into lists orig_date=[] orig_time=[] movements=[] for i in file: tempsplit=i.split(' ') orig_date.append(tempsplit[0]) orig_time.append(tempsplit[1]) movements.append(tempsplit[2]) #d = [datetime.strptime(date, "%Y-%m-%d").date() for date in orig_date] #string to datetime conversion #t=[datetime.strptime(time, "%H:%M:%S.%f").time() for time in orig_time] #string to datetime conversion # """ putting date and time together""" dt_fmt = '%Y-%m-%d %H:%M:%S.%f' #your_dt = datetime.datetime.strptime(d + ' ' +t, dt_fmt) timestamps = [] for col_dt in zip(orig_date , orig_time): new_dt_str = ' '.join(col_dt) new_dt = datetime.datetime.strptime(new_dt_str, dt_fmt) timestamps.append(new_dt) #print(timestamps[1].tzinfo) converted_dates=[] def convert_local_timezone(converted_dates): for date in timestamps: local_tz = pytz.timezone('Europe/Copenhagen') local_time = date.replace(tzinfo=pytz.utc).astimezone(local_tz) converted_dates.append(local_time) return converted_dates CEU_times=convert_local_timezone(timestamps) print(timestamps[0]) print(CEU_times[0])