草庐IT

Primitives-DateTime

全部标签

python - 如何从 datetime.datetime 对象中提取小时和分钟?

我需要从datetime.datetime中提取一天中的时间created_at返回的对象属性,但我该怎么做呢?这是我获取datetime.datetime对象的代码。fromdatetimeimport*importtweepyconsumer_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

python - 如何从 datetime.datetime 对象中提取小时和分钟?

我需要从datetime.datetime中提取一天中的时间created_at返回的对象属性,但我该怎么做呢?这是我获取datetime.datetime对象的代码。fromdatetimeimport*importtweepyconsumer_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

python - 将 unixtime 转换为 datetime 对象并再次返回(时间转换函数对)

我正在尝试编写一对函数,dt和ut,它们在正常的unix时间(自1970-01-0100以来的秒数)之间来回转换:00:00UTC)和一个Python日期时间对象。如果dt和ut是正确的倒数,那么这段代码将打印两次相同的时间戳:importtime,datetime#Convertaunixtimeutoadatetimeobjectd,andviceversadefdt(u):returndatetime.datetime.fromtimestamp(u)defut(d):returntime.mktime(d.timetuple())u=1004260000printu,"-->"

python - 将 unixtime 转换为 datetime 对象并再次返回(时间转换函数对)

我正在尝试编写一对函数,dt和ut,它们在正常的unix时间(自1970-01-0100以来的秒数)之间来回转换:00:00UTC)和一个Python日期时间对象。如果dt和ut是正确的倒数,那么这段代码将打印两次相同的时间戳:importtime,datetime#Convertaunixtimeutoadatetimeobjectd,andviceversadefdt(u):returndatetime.datetime.fromtimestamp(u)defut(d):returntime.mktime(d.timetuple())u=1004260000printu,"-->"

python - 获取 datetime.datetime.fromtimestamp() 使用的时区

是否有可能,如果是,如何获取datetime.datetime使用的时区(即UTC偏移量或具有该偏移量的datetime.timezone实例).fromtimestamp()将POSIX时间戳(自纪元以来的秒数)转换为datetime对象?datetime.datetime.fromtimestamp()将POSIX时间戳转换为朴素的datetime对象(即没有tzinfo),但这样做使用系统的语言环境将其调整为本地时区和当时有效的UTC偏移量。例如,使用UTC时间2008年12月27日午夜的日期(距纪元40*356*86400秒):>>>datetime.datetime.from

python - 获取 datetime.datetime.fromtimestamp() 使用的时区

是否有可能,如果是,如何获取datetime.datetime使用的时区(即UTC偏移量或具有该偏移量的datetime.timezone实例).fromtimestamp()将POSIX时间戳(自纪元以来的秒数)转换为datetime对象?datetime.datetime.fromtimestamp()将POSIX时间戳转换为朴素的datetime对象(即没有tzinfo),但这样做使用系统的语言环境将其调整为本地时区和当时有效的UTC偏移量。例如,使用UTC时间2008年12月27日午夜的日期(距纪元40*356*86400秒):>>>datetime.datetime.from

python - 从 SQL 数据库导入表并按日期过滤行时,将 Pandas 列解析为 Datetime

我有一个DataFrame列名为date。我们如何将“日期”列转换/解析为DateTime对象?我使用sql.read_frame()从Postgresql数据库加载了日期列。date列的示例是2013-04-04。我想要做的是选择数据框中的所有行,这些行在特定时期内具有日期列,例如在2013-04-01之后和2013-04-之前04.我在下面的尝试给出了错误'Series'objecthasnoattribute'read'尝试importdateutildf['date']=dateutil.parser.parse(df['date'])错误AttributeErrorTrace

python - 从 SQL 数据库导入表并按日期过滤行时,将 Pandas 列解析为 Datetime

我有一个DataFrame列名为date。我们如何将“日期”列转换/解析为DateTime对象?我使用sql.read_frame()从Postgresql数据库加载了日期列。date列的示例是2013-04-04。我想要做的是选择数据框中的所有行,这些行在特定时期内具有日期列,例如在2013-04-01之后和2013-04-之前04.我在下面的尝试给出了错误'Series'objecthasnoattribute'read'尝试importdateutildf['date']=dateutil.parser.parse(df['date'])错误AttributeErrorTrace

python - 将 pandas 时间序列从 object dtype 重新索引为 datetime dtype

我有一个不被识别为DatetimeIndex的时间序列,尽管它被具有有效日期的标准YYYY-MM-DD字符串索引。将它们强制为有效的DatetimeIndex似乎不够优雅,让我觉得我做错了什么。我读入(其他人的惰性格式)包含无效日期时间值的数据并删除了这些无效观察结果。In[1]:df=pd.read_csv('data.csv',index_col=0)In[2]:printdf['2008-02-27':'2008-03-02']Out[2]:count2008-02-27202008-02-2802008-02-29272008-02-3002008-02-3102008-03-

python - 将 pandas 时间序列从 object dtype 重新索引为 datetime dtype

我有一个不被识别为DatetimeIndex的时间序列,尽管它被具有有效日期的标准YYYY-MM-DD字符串索引。将它们强制为有效的DatetimeIndex似乎不够优雅,让我觉得我做错了什么。我读入(其他人的惰性格式)包含无效日期时间值的数据并删除了这些无效观察结果。In[1]:df=pd.read_csv('data.csv',index_col=0)In[2]:printdf['2008-02-27':'2008-03-02']Out[2]:count2008-02-27202008-02-2802008-02-29272008-02-3002008-02-3102008-03-