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

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

问题描述

通俗地说,ndb.DatePropertyndb.DateTimeProperty 有什么区别?我什么时候使用哪个?例如,我的意图是使用参数 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 datetime 模块的相应类(日期、时间、日期时间)的值.三者中最通用的是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天全站免登陆