Why does strptime from datetime not give me the correct hours?

烂漫一生 提交于 2021-01-29 20:17:22

问题


I am dealing with hourly data in which the date is stored in 4 different arrays, one for day, month, year, and hour. I am running a for-loop to rather store these dates as strings with this format: '01/01/1946 0'

My code looks something like this:

import numpy as np
from datetime import datetime as dt
import matplotlib.dates as mdates

for nn in range(nnn):
    y1 = int(yr[nn])
    m1 = int(mon[nn])
    d1 = int(day[nn])
    h1 = int(hr[nn])
    
    #In the the last string we are specifying the format
    datenow = dt.strptime(str(m1)+'/'+str(d1)+'/'+str(y1) + ' '+ str(h1) , '%m/%d/%Y %H').date()    
    ndaten = datenow.toordinal()
    
    allnewdate[nn] = ndaten

When I check allnewdate with mdates.num2str(allnewdates) it appears that all hours are defined as 0 at each point instead of parsing through the 23 hours of the day.

What might be wrong?

来源:https://stackoverflow.com/questions/62490296/why-does-strptime-from-datetime-not-give-me-the-correct-hours

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!