A useful time transform util, transforms between string, timestamp and datetime format
Project description
TimeKong
Time converter between timestamp, string and datetime.
Installation
You can install time-kong
simply with pip
:
pip install time-kong
Usages
TimeKong
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'
TimeGen
from time_kong import TimeGen
# generate time in second quickly
print "42 milliseconds is %s second" % TimeGen.n_milliseconds(42)
print "42 seconds is %s seconds" % TimeGen.n_seconds(42)
print "42 minutes is %s seconds" % TimeGen.n_minutes(42)
print "42 hours is %s seconds" % TimeGen.n_hours(42)
print "42 days is %s seconds" % TimeGen.n_days(42)
print "42 months is %s seconds" % TimeGen.n_months(42)
print "42 years is %s seconds" % TimeGen.n_years(42)
# 42 milliseconds is 0.042 second
# 42 seconds is 42 seconds
# 42 minutes is 2520 seconds
# 42 hours is 151200 seconds
# 42 days is 3628800 seconds
# 42 months is 108864000 seconds
# 42 years is 39735360000 seconds
Constants
TimeGen.ONE_MILLISECOND
TimeGen.ONE_SECOND
TimeGen.ONE_MINUTE_SECONDS
TimeGen.ONE_HOUR_SECONDS
TimeGen.ONE_DAY_SECONDS
TimeGen.ONE_MONTH_SECONDS
TimeGen.ONE_YEAR_SECONDS
Author
time-kong is developed and maintained by fanwei.zeng (stayblank@gmail.com). It can be found here:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
time-kong-0.0.2.tar.gz
(2.9 kB
view details)
File details
Details for the file time-kong-0.0.2.tar.gz
.
File metadata
- Download URL: time-kong-0.0.2.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.13.0 setuptools/18.5 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f6a8368787a04f8adf83a45b7e2fd8531cc906a5af0d2fa4d2faf44c09de3bb |
|
MD5 | 87bc9b91783375c9136d3b7050cf12d9 |
|
BLAKE2b-256 | af10bdf42b276527e02fbc8a4b3baa376a8b9026d0717a3c2c6ed7e080731e8d |