如何使用 UliEngineering 在 Python 中检查 datetime 是否为每月第一天
你可以使用 UliEngineering Python 库轻松地检查 datetime 值是否为每月的第一天:
is_first_day_of_month.py
import numpy as np
from UliEngineering.Utils.Date import *
# 检查单个日期
print(f"Is 2024-01-01 first of month? {is_first_day_of_month('2024-01-01')}")
print(f"Is 2024-01-15 first of month? {is_first_day_of_month('2024-01-15')}")
# 检查 NumPy datetime64 数组
dates = np.array(['2024-01-01', '2024-01-15', '2024-02-01', '2024-03-15'], dtype='datetime64[D]')
result = is_first_day_of_month(dates)
print(f"\nFirst of month check: {result}")示例输出
is_first_day_of_month_output.txt
Is 2024-01-01 first of month? True
Is 2024-01-15 first of month? False
First of month check: [ True False True False]is_first_day_of_month() 函数既适用于单个日期,也适用于 NumPy datetime64 数组,对于数组输入会返回布尔数组。
相关文章
- 如何使用 UliEngineering 在 Python 中检查 datetime 是否为每周第一天
- 如何使用 UliEngineering 在 Python 中从 NumPy datetime64 数组提取日期
- 如何使用 UliEngineering 在 Python 中检查 datetime 是否为月份变更
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow