如何仅从Python日期时间对象获取日期

时间:2020-02-26 13:50:54

标签: python datetime

假设我有以下日期时间对象:

aDateTime = datetime.datetime(2020, 2, 26, 12, 30)

现在,我只想提取该对象的日期。我尝试了以下

aDateTime.date

这给了我输出:

<built-in method time of datetime.datetime object at 0x000001FD3A1E85A0>

怎么了?

3 个答案:

答案 0 :(得分:1)

在括号中使用aDateTime.date()

答案 1 :(得分:0)

要在类中调用方法,请使用括号

#a2{
  height: 50px;
  width: 50px;
  border:3px solid red;
  margin-left: 25px;
  margin-top: 25px;
}

答案 2 :(得分:0)

尝试一下:

aDateTime = datetime.datetime(2020, 2, 26, 12, 30)
aDateTime.date()

Output --> datetime.date(2020, 2, 26)