Skip to main content

No project description provided

Project description

编写目的

  1. custom_time.py: 充分扩展python原生包datetime的功能与简化使用方法

  2. time_range.py: 以python原生的range形式遍历时间

使用方法

custom_time.py

一. 使用字符串初始化

from custom_time import CustomTime
# 直接输入字符串,无需指定解析格式
CustomTime("2022-01-23 17:00:00")
CustomTime("2022-01-23-17.00.00")
# 指定希望输出的时间格式
CustomTime("2022-01-23 17:00:00", "%Y-%m-%d-%H-%M-%S")

二. 获取当前时间

# 使用默认的时间格式, 默认为"%Y-%m-%d %H:%M:%S"
now = CustomTime.now()
# 指定希望输出的时间格式
now = CustomTime.now("%Y-%m-%d-%H-%M-%S")

三. 输出时间字符串

a =  CustomTime.now()
print(a.str)

四. 可直接使用datetime的方法

五. 时间的计算,支持的参数years, months, days, seconds, microseconds,milliseconds, minutes, hours, weeks

注意: datetime不支持days,本模块支持

now = CustomTime.now()
yesterday = now.delta(days=-1)
tomorrow = now.delta(days=1)

六. 其他方法

now = CustomTime.now()
# 获取整点
now.oclock()
# 获取日期
now.date() now.date("%Y-%m-%d")

TimeRange.py

  1. 1.遍历时间范围

    from custom_time import TimeRange
    start_time = CustomTime.now()
    end_time = start_time.delta(days=10)
    for current in TimeRange(start_time, end_time, days=1):
            print(current)

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

custom_time-1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

custom_time-1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file custom_time-1.0.tar.gz.

File metadata

  • Download URL: custom_time-1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.2

File hashes

Hashes for custom_time-1.0.tar.gz
Algorithm Hash digest
SHA256 e78465b063caf992ab1018a326ef4651bbb8911a89f23fe88b0f59de03efb86d
MD5 4b208064c64885ee0012551297e74800
BLAKE2b-256 9f6be50080160de3f3b359f1a9a6e2792964bd87dbb0a719dd3ef1932f94bbea

See more details on using hashes here.

File details

Details for the file custom_time-1.0-py3-none-any.whl.

File metadata

  • Download URL: custom_time-1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.2

File hashes

Hashes for custom_time-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32fd89cf09fb1d7669085c5c772108db80e82655394477d5e59488887663fce0
MD5 aa89743babe94b44cffe62ade46a7ed7
BLAKE2b-256 fd4bd73a5e135334e121e1f7ace03c93ac2bd56f1952e1229f98f4fde8d7d9fb

See more details on using hashes here.

Supported by

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