import time
import datetime

# 获取当前时间戳
current_timestamp = time.time()
# 将当前时间戳转换为 datetime 对象
current_datetime = datetime.datetime.fromtimestamp(current_timestamp)

# 计算距离当前时间最近的整点或 30 分时刻
if current_datetime.minute < 30:
    target_datetime = current_datetime.replace(minute=0, second=0, microsecond=0)
else:
    target_datetime = current_datetime.replace(minute=30, second=0, microsecond=0)

# 将目标 datetime 对象转换为时间戳
target_timestamp = target_datetime.timestamp()

print(f"当前时间戳: {current_timestamp}")
print(f"目标时间戳: {target_timestamp}")

# 进行时间戳比对
if current_timestamp == target_timestamp:
    print("当前时间就是目标时间。")
elif current_timestamp < target_timestamp:
    print(f"当前时间早于目标时间，还需等待 {target_timestamp - current_timestamp} 秒。")
else:
    print(f"当前时间晚于目标时间，已经过去了 {current_timestamp - target_timestamp} 秒。")
