37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
# 测试第一个宝箱的时间计算
|
||
|
|
created_at_str = "2025-12-14T10:44:38"
|
||
|
|
countdown_seconds = 300
|
||
|
|
|
||
|
|
# 解析创建时间
|
||
|
|
created_time = datetime.fromisoformat(created_at_str.replace('Z', '+00:00')) if isinstance(created_at_str, str) else created_at_str
|
||
|
|
print(f"Created time: {created_time}")
|
||
|
|
|
||
|
|
# 获取当前时间
|
||
|
|
now = datetime.now()
|
||
|
|
print(f"Current time: {now}")
|
||
|
|
|
||
|
|
# 计算经过的时间
|
||
|
|
elapsed = (now - created_time).total_seconds()
|
||
|
|
print(f"Elapsed seconds: {elapsed}")
|
||
|
|
|
||
|
|
# 计算剩余时间
|
||
|
|
time_remaining = max(0, int(countdown_seconds - elapsed))
|
||
|
|
print(f"Time remaining: {time_remaining}")
|
||
|
|
|
||
|
|
# 测试第二个宝箱的时间计算
|
||
|
|
created_at_str2 = "2025-12-14T04:32:51"
|
||
|
|
countdown_seconds2 = 298
|
||
|
|
|
||
|
|
# 解析创建时间
|
||
|
|
created_time2 = datetime.fromisoformat(created_at_str2.replace('Z', '+00:00')) if isinstance(created_at_str2, str) else created_at_str2
|
||
|
|
print(f"\nCreated time 2: {created_time2}")
|
||
|
|
|
||
|
|
# 计算经过的时间
|
||
|
|
elapsed2 = (now - created_time2).total_seconds()
|
||
|
|
print(f"Elapsed seconds 2: {elapsed2}")
|
||
|
|
|
||
|
|
# 计算剩余时间
|
||
|
|
time_remaining2 = max(0, int(countdown_seconds2 - elapsed2))
|
||
|
|
print(f"Time remaining 2: {time_remaining2}")
|