我需要从 datetime.datetime 中提取一天中的时间 created_at 返回的对象 属性,但我该怎么做呢?
这是我获取 datetime.datetime 对象的代码。
from datetime import *
import tweepy
consumer_key = ''
consumer_secret = ''
access_token = ''
access_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
tweets = tweepy.Cursor(api.home_timeline).items(limit = 2)
t1 = datetime.strptime('Wed Jun 01 12:53:42 +0000 2011', '%a %b %d %H:%M:%S +0000 %Y')
for tweet in tweets:
print (tweet.created_at - t1)
t1 = tweet.created_at
我只需要从 t1
中提取小时和分钟。
最佳答案
我不知道你想如何格式化,但你可以这样做:
print("Created at %s:%s" % (t1.hour, t1.minute))
例如。
关于python - 如何从 datetime.datetime 对象中提取小时和分钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25754405/