Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
datetime
#1
I have a document with dates and times inside.
I have converted them into datetime objects, but now
I am having trouble in putting the date and time together.
For instance, the first date is 2015-01-25 and the first time
is 14:05:41.274647.
Now I would like to see only one number of the format "%Y-%m-%d "%H:%M:%S.%f"
but if I write on python date 'and' time, I only get the time (see last line of the code).
How do I get them both?

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 datetime, 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])


orig_dates_list = [datetime.strptime(date, "%Y-%m-%d").date() for date in orig_date] #string to datetime conversion
orig_time_list=[datetime.strptime(time, "%H:%M:%S.%f").time() for time in orig_time] #string to datetime conversion
#


print(orig_dates_list[0] and orig_time_list[0]) #date 'and' time

by the way, despite of what I wrote on the last line,
I must be able to get the format "%Y-%m-%d "%H:%M:%S.%f"
for the whole list, and not just for the first value.
Reply


Messages In This Thread
datetime - by mcgrim - May-22-2019, 09:28 AM
RE: datetime - by DeaD_EyE - May-22-2019, 10:03 AM
RE: datetime - by mcgrim - May-22-2019, 10:25 AM
RE: datetime - by DeaD_EyE - May-22-2019, 11:22 AM
RE: datetime - by mcgrim - May-22-2019, 11:33 AM

Forum Jump:

User Panel Messages

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