是否存在比任何有效 datetime.datetime(...) 都小的对象?
Is there an object that compares smaller than any valid datetime.datetime(...)?
是否有 datetime
的 MIN
常量?
我需要它来表示资源的到期日期,我想要一个 datetime
表示 "always expires" 作为默认值(而不是 None
所以我可以使用无论如何都进行相同的到期比较)。
所以现在我使用 datetime.datetime(datetime.MINYEAR,1,1,0,0,tzusc())
作为我的 MIN datetime
但我想知道是否有其他方式来表示 "the lowest possible time"(即使它不是 datetime
).
您可以使用 time.gmtime(0)
纪元。
The epoch is the point where the time starts. On January 1st of that year, at 0 hours, the “time since the epoch” is zero. For Unix, the epoch is 1970. To find out what the epoch is, look at gmtime(0).
datetime.datetime.fromtimestamp(0)
它会给你:
datetime.datetime(1970, 1, 1, 1, 0)
Return the local date corresponding to the POSIX timestamp, such as is
returned by time.time(). This may raise ValueError, if the timestamp
is out of the range of values supported by the platform C localtime()
function. It’s common for this to be restricted to years from 1970
through 2038. Note that on non-POSIX systems that include leap seconds
in their notion of a timestamp, leap seconds are ignored by
fromtimestamp().
你可以试试 - datetime.datetime.min
. According to documentation -
datetime.min
The earliest representable datetime, datetime(MINYEAR, 1, 1, tzinfo=None).
是否有 datetime
的 MIN
常量?
我需要它来表示资源的到期日期,我想要一个 datetime
表示 "always expires" 作为默认值(而不是 None
所以我可以使用无论如何都进行相同的到期比较)。
所以现在我使用 datetime.datetime(datetime.MINYEAR,1,1,0,0,tzusc())
作为我的 MIN datetime
但我想知道是否有其他方式来表示 "the lowest possible time"(即使它不是 datetime
).
您可以使用 time.gmtime(0)
纪元。
The epoch is the point where the time starts. On January 1st of that year, at 0 hours, the “time since the epoch” is zero. For Unix, the epoch is 1970. To find out what the epoch is, look at gmtime(0).
datetime.datetime.fromtimestamp(0)
它会给你:
datetime.datetime(1970, 1, 1, 1, 0)
Return the local date corresponding to the POSIX timestamp, such as is returned by time.time(). This may raise ValueError, if the timestamp is out of the range of values supported by the platform C localtime() function. It’s common for this to be restricted to years from 1970 through 2038. Note that on non-POSIX systems that include leap seconds in their notion of a timestamp, leap seconds are ignored by fromtimestamp().
你可以试试 - datetime.datetime.min
. According to documentation -
datetime.min
The earliest representable datetime, datetime(MINYEAR, 1, 1, tzinfo=None).