更新时间:2023-01-28 10:59:57
根据datetime.now(tz=None)
的文档:
返回当前本地日期和时间.如果可选参数 tz
为 None
或未指定,则类似于 today()
,但是,如果可能,提供比可以获得的精度更高的精度通过 time.time()
时间戳(例如,这在提供 C gettimeofday()
函数的平台上是可能的).
Return the current local date and time. If optional argument
tz
isNone
or not specified, this is liketoday()
, but, if possible, supplies more precision than can be gotten from going through atime.time()
timestamp (for example, this may be possible on platforms supplying the Cgettimeofday()
function).
Else tz
必须是 tzinfo
类子类的实例,当前日期和时间转换为 tz
的时区.在这种情况下,结果等效于 tz.fromutc(datetime.utcnow().replace(tzinfo=tz))
.
Else tz
must be an instance of a class tzinfo
subclass, and the current date and time are converted to tz
‘s time zone. In this case the result is equivalent to tz.fromutc(datetime.utcnow().replace(tzinfo=tz))
.
因此 datetime.now()
尽可能提供更高的精度.
Thus datetime.now()
supplies more precision if possible.