How to extract hours and minutes from a datetime.datetime object?

前端 未结 4 1406
渐次进展
渐次进展 2020-12-15 02:25

I am required to extract the time of the day from the datetime.datetime object returned by the created_at attribute. But I do not understand how to do that. This is my code

4条回答
  •  感情败类
    2020-12-15 03:19

    datetime has fields hour and minute. So to get the hours and minutes, you would use t1.hour and t1.minute.

    However, when you subtract two datetimes, the result is a timedelta, which only has the days and seconds fields. So you'll need to divide and multiply as necessary to get the numbers you need.

提交回复
热议问题