将python时间戳转换为一年中的某天

编程入门 行业动态 更新时间:2024-10-28 02:33:29
本文介绍了将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时间戳转换为一年中的某天

本文发布于:2023-10-23 15:58:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521316.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   年中   某天   时间   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!