python函数`datetime.now()`和`datetime.today()`有什么区别? [英] What is the difference between python functions `datetime.now()` and `datetime.today()`?

查看:781
本文介绍了python函数`datetime.now()`和`datetime.today()`有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

python函数 datetime.now() datetime.today()有什么区别?

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


在[1]:从datetime导入datetime

In [1]: from datetime import datetime

在[2]:datetime .now()

In [2]: datetime.now()

Out [2]:datetime.datetime(2015,9,11,12,12,28,909842)

Out[2]: datetime.datetime(2015, 9, 11, 12, 8,28, 909842)

在[3]中:datetime.today()

In [3]: datetime.today()

在[3]:datetime.datetime(2015,9,11,12,8 ,45,175839)

Out[3]: datetime.datetime(2015, 9, 11, 12,8, 45, 175839)

预先感谢。

推荐答案

datetime.datetime.now()使用tzinfo作为关键字参数,但 datetime.today()不使用任何关键字参数。

datetime.datetime.now() takes tzinfo as keyword argument but datetime.today() does not take any keyword arguments.

默认情况下, now()使用 datetime.datetime.now(tz = None)

文档中引用的内容: https ://docs.python.org/3.6/library/datetime.html#datet ime.datetime.now


datetime.now()返回当前本地日期和时间。如果可选的
参数tz为None或未指定,则类似于today(),但是,如果
可能,则提供比通过
经过time.time()可获得的精度更高的精度。时间戳(例如,在提供C gettimeofday()函数的
平台上可能是可行的)。

datetime.now() return the current local date and time. 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).

这篇关于python函数`datetime.now()`和`datetime.today()`有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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