查找python datetime是否没有时间信息 [英] Finding if a python datetime has no time information

查看:43
本文介绍了查找python datetime是否没有时间信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想捕获这样的值(在日期时间中没有时间信息"):

I want to trap values that are like this (in which there is not 'time info' on the datetime):

datetime.datetime(2009, 4, 6, 0, 0)

除了测试小时/分钟/秒之外,还有其他更好的方法来检测这些值吗?

Is there a better way to detect these values other than testing hour/minute/second?

if value.hour == 0 and value.minute == 0 and value.second == 0:
     # do stuff

推荐答案

在Python 3.4和更早版本中

时间方法在这里起作用.如果时间信息为零,则评估为布尔值false.

In Python 3.4 and earlier

The time method works here. Evaluates as boolean false if there's zero'd-out time info.

if not value.time():
    # do stuff

这篇关于查找python datetime是否没有时间信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆