Time converter between timestamp, string and datetime.
You can install time-kong
simply with pip
:
pip install time-kong
Convert time between timestamp, string and datetime:
from datetime import datetime
from time_kong import TimeKong
ts = 1558883766.864879
TimeKong.timestamp2string(ts, formatter="%Y-%m-%d %H:%M:%S.%f")
# '2019-05-26 23:16:06.864879'
TimeKong.timestamp2datetime(ts)
# datetime.datetime(2019, 5, 26, 23, 16, 6, 864879)
ds = '2019-05-26 23:16:06.864879'
TimeKong.string2timestamp(ds, formatter="%Y-%m-%d %H:%M:%S.%f")
# 1558883766.864879
TimeKong.string2datetime(ds, formatter="%Y-%m-%d %H:%M:%S.%f")
# datetime.datetime(2019, 5, 26, 23, 16, 6, 864879)
dt = datetime(year=2019, month=5, day=26, hour=22, minute=42, second=26, microsecond=864879)
TimeKong.datetime2timestamp(dt)
# 1558881746.864879
TimeKong.datetime2string(dt, formatter="%Y-%m-%d %H:%M:%S.%f")
# '2019-05-26 22:42:26.864879'
Constants included:
TimeKong.NANOSECOND
TimeKong.MICROSECOND
TimeKong.MILLISECOND
TimeKong.SECOND
TimeKong.MINUTE
TimeKong.HOUR
TimeKong.DAY
TimeKong.WEEK
TimeKong.MONTH
TimeKong.YEAR
time-kong is developed and maintained by fanwei.zeng ([email protected]). It can be found here: