https://github.com/serfend/sgtpyutils
sgtpyutils is a public library for use
https://github.com/serfend/sgtpyutils
Last synced: 6 months ago
JSON representation
sgtpyutils is a public library for use
- Host: GitHub
- URL: https://github.com/serfend/sgtpyutils
- Owner: serfend
- Created: 2022-06-05T10:37:44.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-02T02:45:23.000Z (over 1 year ago)
- Last Synced: 2025-11-27T20:06:11.343Z (7 months ago)
- Language: Python
- Homepage: https://pypi.org/project/sgtpyutils
- Size: 401 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# What?
sgtpyutils is python module for common utils.
## Install
```shell
pip install sgtpyutils
```
## Usage
### 日志处理
```python
from sgtpyutils.logger import logger
logger.debug('调试')
logger.info('信息')
logger.warning('警告')
```
### 时间处理
```python
from sgtpyutils.datetime import DateTime
# 当前时间
print(DateTime()) # 2023-09-19 14:50:43.570560+08:00
# 指定日期
print(DateTime('2023-09-19')) # 2023-09-19 00:00:00+08:00
# 指定时间
print(DateTime('2023-09-19 14:50:43')) # 2023-09-19 14:50:43+08:00
# 指定时间戳
print(DateTime(1695106243000)) # 2023-09-19 14:50:43+08:00
# 指定时间及时区
print(DateTime('2023-09-19T14:50:43+07:00')) # 2023-09-19 14:50:43+07:00
# 计算时间差
print((DateTime('2023-09-20') - '2023-09-19').total_seconds()) # 86400.0
print((DateTime('2023-09-20') - 60 * 1000)) # 2023-09-19 23:59:00+08:00
# 获取相对时间
print(DateTime('2023-09-20').toRelativeTime('2023-09-20 14:23')) # 14小时前
print(DateTime('2023-09-20 10:00:00').toRelativeTime('2023-09-20 10:01:00')) # 1分钟后
print(DateTime('2023-01-20 10:00:00').toRelativeTime()) # xxx年前
```
## Status
