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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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