util¶
time math calculation.
-
rolex.util.
from_ordinal
(days)[source]¶ Create a date object that number
days
of days after 0000-00-00.
-
rolex.util.
to_utctimestamp
(a_datetime)[source]¶ Calculate number of seconds from UTC 1970-01-01 00:00:00.
When:
- dt doesn’t have tzinfo: assume it’s a utc time.
- dt has tzinfo: use tzinfo.
WARNING, if your datetime object doens’t have
tzinfo
, make sure it’s a UTC time, but NOT a LOCAL TIME.中文文档
计算时间戳, 若:
- 不带tzinfo: 则默认为是UTC time。
- 带tzinfo: 则使用tzinfo。
-
rolex.util.
from_utctimestamp
(timestamp)[source]¶ Create a datetime object that number of seconds after UTC 1970-01-01 00:00:00. If you want local time, use
from_timestamp()
This method support negative timestamp.
Returns: non-timezone awared UTC datetime. 中文文档
返回一个在UTC 1970-01-01 00:00:00 之后 #timestamp 秒后的时间。默认为 UTC时间。即返回的datetime不带tzinfo
-
rolex.util.
to_utc
(a_datetime, keep_utc_tzinfo=False)[source]¶ Convert a time awared datetime to utc datetime.
Parameters: - a_datetime – a timezone awared datetime. (If not, then just returns)
- keep_utc_tzinfo – whether to retain the utc time zone information.
中文文档
将一个带时区的时间转化成UTC时间。而对于UTC时间而言, 有没有时区信息都无所谓了。
-
rolex.util.
utc_to_tz
(utc_datetime, tzinfo, keep_tzinfo=False)[source]¶ Convert a UTC datetime to a time awared local time
Parameters: - utc_datetime –
- tzinfo –
- keep_tzinfo –