Python 2.7 如何使用Python从hdf格式的文件名中提取日期?
我有一个hdf格式的文件。我想从文件名中提取日期?如何使用Python 2.7做到这一点 我试过使用split命令和regex,但不起作用 我的文件名如下所示:Python 2.7 如何使用Python从hdf格式的文件名中提取日期?,python-2.7,hdf,Python 2.7,Hdf,我有一个hdf格式的文件。我想从文件名中提取日期?如何使用Python 2.7做到这一点 我试过使用split命令和regex,但不起作用 我的文件名如下所示: CAL_LID_L2_05kmAlay-Standard-V4-20.2012-08-01T06-24-24.hdf 您需要将文件名分成多个部分,并使用以下方法从中解析datetime部分: 输出: 2012-08-01T06-24-24 # the cutout string 2012-08-01 06:24:24 # th
CAL_LID_L2_05kmAlay-Standard-V4-20.2012-08-01T06-24-24.hdf
您需要将文件名分成多个部分,并使用以下方法从中解析datetime部分:
输出:
2012-08-01T06-24-24 # the cutout string
2012-08-01 06:24:24 # the datetime object
2012-08-01 # only the date()
Doku:
dt_str=fn.split(“.”[-2].rstrip(“ZN”)
现在格式为datetime.data。我是否可以将其添加到带有日期的excel表格中separately@Sree你为什么不查一下呢?已经试过文档了吗?datetime对象具有从中获取年、月、日、小时、分钟和秒的方法:
2012-08-01T06-24-24 # the cutout string
2012-08-01 06:24:24 # the datetime object
2012-08-01 # only the date()