如何使用 UliEngineering 在 Python 中生成按天的 datetime 数组
你可以使用 UliEngineering Python 库轻松生成一段日期范围内的 NumPy datetime64 数组:
generate_days.py
import numpy as np
from UliEngineering.Utils.Date import *
# 生成 2024 年 1 月的 datetime 数组
days = generate_days("2024-01-01", "2024-01-31")
print(f"Days in January 2024: {len(days)}")
print(f"First day: {days[0]}")
print(f"Last day: {days[-1]}")
# 生成一周的 datetime 数组
days = generate_days("2024-01-01", "2024-01-07")
print(f"\nDays in a week: {days}")示例输出
generate_days_output.txt
Days in January 2024: 31
First day: 2024-01-01
Last day: 2024-01-31
Days in a week: ['2024-01-01' '2024-01-02' '2024-01-03' '2024-01-04' '2024-01-05'
'2024-01-06' '2024-01-07']generate_days() 函数返回一个 NumPy datetime64 数组,包含从起始日期(含)到结束日期(含)的所有天数。
相关文章
- 如何使用 UliEngineering 在 Python 中生成按年的 datetime 数组
- 如何使用 UliEngineering 在 Python 中生成按月的 datetime 数组
- 如何使用 UliEngineering 在 Python 中从 NumPy datetime64 数组提取月份
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow