datetime_ms -- Support for BSON UTC Datetime#
Tools for representing the BSON datetime type.
在 4.3 版本加入.
- class bson.datetime_ms.DatetimeMS(value: int | datetime)#
Represents a BSON UTC datetime.
BSON UTC datetimes are defined as an int64 of milliseconds since the Unix epoch. The principal use of DatetimeMS is to represent datetimes outside the range of the Python builtin
datetimeclass when encoding/decoding BSON.To decode UTC datetimes as a
DatetimeMS, datetime_conversion inCodecOptionsmust be set to 'datetime_ms' or 'datetime_auto'. See 处理超出范围的日期时间 for details.- Parameters:
value: An instance of
datetime.datetimeto be represented as milliseconds since the Unix epoch, or int of milliseconds since the Unix epoch.
- as_datetime(codec_options: CodecOptions = CodecOptions(document_class=dict, tz_aware=False, uuid_representation=UuidRepresentation.UNSPECIFIED, unicode_decode_error_handler='strict', tzinfo=None, type_registry=TypeRegistry(type_codecs=[], fallback_encoder=None), datetime_conversion=DatetimeConversion.DATETIME)) datetime#
Create a Python
datetimefrom this DatetimeMS object.- Parameters:
codec_options: A CodecOptions instance for specifying how the resulting DatetimeMS object will be formatted using
tz_awareandtz_info. Defaults toDEFAULT_CODEC_OPTIONS.