Skip to main content

Python操作工具合集

Project description

Operate Tools

OSCS Status

Python操作工具合集

Author: Joker-desire

OSCS

OSCS Status

安装

pip3 install operate-tools

# v1.0.5版本对整体进行了重写,对于之前的版本请使用以下方式进行安装
pip3 install operate-tools==1.0.4

功能如下

  1. 日期操作
  2. 星期操作
  3. 时间操作
  4. 文件操作
  5. ……

功能说明

时间日期工具-Date

from operate_tools import Date

方法

1. 获取当前日期
Date.now(fmt="%Y-%m-%d %H:%M:%S")
2. 获取前几天的日期
Date.days_before(days=31)

3. 获取后几天的日期

Date.days_after(days=31)
4. 获取昨天的日期
Date.yesterday(fmt="%Y-%m-%d")
5. 获取明天的日期
Date.tomorrow(fmt="%Y-%m-%d")
6. 获取上周的日期
Date.last_week(fmt="%Y-%m-%d")

7. 获取下周的日期

Date.next_week(fmt="%Y-%m-%d")
8. 获取上个月的日期
Date.last_month(fmt="%Y-%m-%d")
9. 获取下个月的日期
Date.next_month(fmt="%Y-%m-%d")
10. 获取开始到结束日期的每一天日期
Date.every_day("2021-01-01", "2021-01-05")
11. 计算时间差
Date.time_difference("2022-03-17 16:15:38", "2022-03-17 16:15:40")
12. 判断当前时间是否在指定时间范围内
Date.is_within_time_range(start="00:00", end="09:00")
13. 时间戳转时间
Date.timestamp_to_time("1626441600000", unit="ms")
Date.timestamp_to_time("1626441600", unit="s")
Date.timestamp_to_time("1626441600000", unit="ms", fmt="%Y-%m-%d")
14. 获取当前星期
Date.now_week()
Date.now_week(lang='zh')
Date.now_week(lang='en')
15. 获取某一日期的星期
Date.week("2023-07-19")
Date.week(date="2023-07-19", lang="zh")
Date.week(date="2023-07-19", lang="en")

文件工具-File

from operate_tools import File

方法

1. 获取文件的编码格式
File.encode("test/file.txt")
2. 编码格式转换
res = File.convert_encode("test/file.txt", "utf-8")

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

operate_tools-1.0.6.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

operate_tools-1.0.6-py3-none-any.whl (5.9 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