DateProperty和DateTimeProperty之间的区别 [英] difference between DateProperty and DateTimeProperty

查看:179
本文介绍了DateProperty和DateTimeProperty之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通俗地说, ndb.DateProperty ndb.DateTimeProperty 之间有什么区别?我什么时候可以用它?例如,我的意图是使用param auto_now_add = True

In layman's term, what's the difference between ndb.DateProperty and ndb.DateTimeProperty? When would I use which? For example, my intent is to use either with the param auto_now_add=True.

推荐答案

通过文档


这些值取属于标准Python日期时间模块的相应类(日期,时间,日期时间)的值。三者中最一般的是DateTimeProperty,它表示日历日期和时间;其他人偶尔对仅需要日期(例如出生日期)或仅仅一次(例如会议时间)的特殊用途有用。由于技术原因,DateProperty和TimeProperty是DateTimeProperty的子类,但不应该依赖于这种继承关系(并且注意它不同于由datetime模块本身定义的基础类之间的继承关系)。

These take values belonging to the corresponding classes (date, time, datetime) of the standard Python datetime module. The most general of the three is DateTimeProperty, which denotes both a calendar date and a time of day; the others are occasionally useful for special purposes requiring just a date (such as a date of birth) or just a time (such as a meeting time). For technical reasons, DateProperty and TimeProperty are subclasses of DateTimeProperty, but you shouldn't depend on this inheritance relationship (and note that it differs from the inheritance relationships between the underlying classes defined by the datetime module itself).

正如预期的那样,如果您不需要任何时间参考(例如:只是日期),则可以使用其中一个,另一个需要完整信息。当你使用其中一种或另一种时,完全取决于你需要的信息。

As expected, one is used if you don't need any reference to the time (eg: just the date), the other when you want the full information. When you would use one or the other completely depends on what information you need at a very precise moment.

这篇关于DateProperty和DateTimeProperty之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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