Skip to main content

A useful time transform util, transforms between string, timestamp and datetime format

Project description

TimeKong

time kong

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

  1. TimeGen.ONE_MILLISECOND
  2. TimeGen.ONE_SECOND
  3. TimeGen.ONE_MINUTE_SECONDS
  4. TimeGen.ONE_HOUR_SECONDS
  5. TimeGen.ONE_DAY_SECONDS
  6. TimeGen.ONE_MONTH_SECONDS
  7. TimeGen.ONE_YEAR_SECONDS

Author

time-kong is developed and maintained by fanwei.zeng (stayblank@gmail.com). It can be found here:

https://github.com/PurpleSun/time_kong

Project details


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)

Uploaded Source

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

Hashes for time-kong-0.0.2.tar.gz
Algorithm Hash digest
SHA256 7f6a8368787a04f8adf83a45b7e2fd8531cc906a5af0d2fa4d2faf44c09de3bb
MD5 87bc9b91783375c9136d3b7050cf12d9
BLAKE2b-256 af10bdf42b276527e02fbc8a4b3baa376a8b9026d0717a3c2c6ed7e080731e8d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page