有人知道如何将这个matlab代码转换为python吗?
for i=1:100
RefTime = datenum('01-Jan-1900 00:00:00');
MyTime=97847+i;
t0=addtodate(RefTime,double(MyTime), 'hour');
date(i)=datestr(t0,'yyyymmddHH');
end
我正在尝试将每小时的数字日期格式(MyTime)转换为参考点(例如,原点)是0100年1月1日00:00到YYYYMMDDHH格式。
答案 0 :(得分:1)
这样的事情:
import datetime
RefTime = datetime.datetime(1900,1,1,0,0,0)
OneHour = datetime.timedelta(0,3600)
date = []
for i in range(100):
#python loop starts at 0, so add 1 to your magic number below
MyTime = 97847 + 1 + i
t0 = RefTime + OneHour * MyTime
date.append(t0.strftime("%Y%m%d%H"))
#now 'date' is a list with 100 strings like "1911030200", etc.