No project description provided
Project description
编写目的
custom_time.py: 充分扩展python原生包datetime的功能与简化使用方法
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.遍历时间范围
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
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)
Built Distribution
Close
Hashes for custom_time-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32fd89cf09fb1d7669085c5c772108db80e82655394477d5e59488887663fce0 |
|
MD5 | aa89743babe94b44cffe62ade46a7ed7 |
|
BLAKE2b-256 | fd4bd73a5e135334e121e1f7ace03c93ac2bd56f1952e1229f98f4fde8d7d9fb |