35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from datetime import datetime, timezone
|
||
|
||
# 模拟创建一个新宝箱的情况
|
||
# 假设现在是UTC时间
|
||
now_utc = datetime.utcnow()
|
||
print(f"Current UTC time: {now_utc}")
|
||
|
||
# 模拟宝箱创建时间(1秒前)
|
||
created_time = datetime.utcnow()
|
||
print(f"Created time: {created_time}")
|
||
|
||
# 模拟3600秒(1小时)倒计时
|
||
countdown_seconds = 3600
|
||
|
||
# 计算经过的时间
|
||
elapsed = (now_utc - created_time).total_seconds()
|
||
print(f"Elapsed seconds: {elapsed}")
|
||
|
||
# 计算剩余时间
|
||
time_remaining = max(0, int(countdown_seconds - elapsed))
|
||
print(f"Time remaining: {time_remaining} seconds")
|
||
|
||
# 转换为分钟和秒
|
||
minutes = time_remaining // 60
|
||
seconds = time_remaining % 60
|
||
print(f"Formatted time remaining: {minutes:02d}:{seconds:02d}")
|
||
|
||
# 测试较老的宝箱情况
|
||
old_created_time = datetime(2025, 12, 14, 10, 0, 0) # 几小时前创建
|
||
old_elapsed = (now_utc - old_created_time).total_seconds()
|
||
old_time_remaining = max(0, int(countdown_seconds - old_elapsed))
|
||
print(f"\nOld chest test:")
|
||
print(f"Old created time: {old_created_time}")
|
||
print(f"Old elapsed seconds: {old_elapsed}")
|
||
print(f"Old time remaining: {old_time_remaining} seconds") |