What is the difference between python functions `datetime.now()` and `datetime.today()`?

前端 未结 3 1147
有刺的猬
有刺的猬 2021-02-03 19:05

What is the difference between python functions datetime.now() and datetime.today() ?

In [1]: from datetime import datetime

3条回答
  •  误落风尘
    2021-02-03 19:45

    See the docs for datetime.today and datetime.now, specifically this part from the latter link:

    If optional argument tz is None or not specified, this is like today(), but, if possible, supplies more precision than can be gotten from going through a time.time() timestamp (for example, this may be possible on platforms supplying the C gettimeofday() function).

    So in your example, both are the same, although specific platforms may provide more precision with datetime.now.

提交回复
热议问题