Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x TypeError:strTime()参数1必须是str,而不是tweepy中的datetime.datetime_Python 3.x_Datetime_Tweepy_Strptime_Strftime - Fatal编程技术网

Python 3.x TypeError:strTime()参数1必须是str,而不是tweepy中的datetime.datetime

Python 3.x TypeError:strTime()参数1必须是str,而不是tweepy中的datetime.datetime,python-3.x,datetime,tweepy,strptime,strftime,Python 3.x,Datetime,Tweepy,Strptime,Strftime,TypeError:strTime()参数1必须是str,而不是datetime.datetime。 我想在上述代码中获取日期时间格式,如下所示: 在“tweet.created_”处 outtweets = [[ tweet.id_str, tweet.created_at.datetime.strptime(tweet.created_at.time, '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%dT%H:%M:%SZ') //ple

TypeError:strTime()参数1必须是str,而不是datetime.datetime。 我想在上述代码中获取日期时间格式,如下所示:

在“tweet.created_”处

    outtweets = [[
    tweet.id_str,
    tweet.created_at.datetime.strptime(tweet.created_at.time, '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%dT%H:%M:%SZ')  //please expected output format below
    tweet.favorite_count,
    tweet.retweet_count,
    ]
    for idx, tweet in enumerate(all_tweets)]


    df = DataFrame(outtweets,columns=["id",
                                      "created_at",
                                      "favorite_count",
                                      "retweet_count",
                                      ])
    print(df.head(10))

tweet.created_at应该已经是一个datetime对象,所以如果您想格式化为字符串,那么datetime.strftime(tweet.created_at,'%Y-%m-%dT%H:%m:%SZ')

i want datetime format output=2021-04-15T18:13:09Z就像我在循环tweet.created_at中写的那样!tweet.created_at应该已经是一个datetime对象,因此如果您想格式化为字符串,
datetime.strftime(tweet.created_at,'%Y-%m-%dT%H:%m:%SZ')
应该可以工作。谢谢您的工作!