# -*- coding: UTF-8 -*-
import random
from datetime import datetime,timedelta
start_time = datetime(2024, 6, 12, 00, 00, 00)
end_time = datetime(2024, 6, 12, 23, 59, 59)
while start_time < end_time:
# datetime.timedelta表示两个 date 对象或者 time 对象,或者 datetime 对象之间的时间间隔,
# 使用固定值 30 秒
# temp = datetime.timedelta(seconds=30)
# 使用随机数随机秒数 (0 - 60 之间的数)
temp = timedelta(seconds=random.randint(0,60))
start_time = start_time + temp
if start_time < end_time:
print(start_time)
'''
timedelta() 参数:
days,
seconds,
microseconds,
milliseconds,
minutes,
hours,
weeks,
'''
'''
输出部分结果:
2024-06-12 23:54:56
2024-06-12 23:55:12
2024-06-12 23:55:54
2024-06-12 23:56:21
2024-06-12 23:56:42
'''
'''
参考:
https://blog.csdn.net/weixin_41331069/article/details/132714017
https://blog.csdn.net/weixin_41261833/article/details/103909724
'''