本文介绍了将python时间戳转换为一年中的某天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将python时间戳转换为一年中的某天:
How can I convert a python timestamp into day of year:
Timestamp('2015-06-01 00:00:00')我想要一个数字,其中1月1日为1,1月2日为2 ... 12月31日为365(非-年)
I want a number where Jan 1 is 1, Jan 2 is 2... Dec 31 is 365 (for a non-leap year)
推荐答案您可能想看看函数 datetime.timetuple() ,它返回 time.struct_time 具有所需属性的对象。它具有一个命名的元组接口,因此您可以按索引或属性名称访问值。
You might want to take a look at the function datetime.timetuple() which returns a time.struct_time object with your desired attribute. It has a named tuple interface, so you can access the values by index or attribute name.
import datetime date = datetime.datetime.strptime("2015-06-01 00:00:00", "%Y-%m-%d %H:%M:%S") print date.timetuple().tm_yday #=> 152更多推荐
将python时间戳转换为一年中的某天
发布评论