28 lines
1020 B
Python
28 lines
1020 B
Python
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
# 模拟数据库中的UTC时间(naive datetime)
|
|||
|
|
db_created_time = datetime(2025, 12, 14, 11, 0, 0) # UTC时间 11:00
|
|||
|
|
|
|||
|
|
# 模拟当前UTC时间
|
|||
|
|
now_utc = datetime.utcnow()
|
|||
|
|
|
|||
|
|
print(f"Database created time (UTC): {db_created_time}")
|
|||
|
|
print(f"Current UTC time: {now_utc}")
|
|||
|
|
|
|||
|
|
# 计算时间差
|
|||
|
|
elapsed = (now_utc - db_created_time).total_seconds()
|
|||
|
|
print(f"Elapsed seconds: {elapsed}")
|
|||
|
|
|
|||
|
|
# 测试60秒倒计时
|
|||
|
|
countdown_seconds = 60
|
|||
|
|
time_remaining = max(0, int(countdown_seconds - elapsed))
|
|||
|
|
print(f"Time remaining for 60s countdown: {time_remaining} seconds")
|
|||
|
|
|
|||
|
|
# 如果是新创建的宝箱(1秒前创建)
|
|||
|
|
recent_created_time = datetime.utcnow() # 当前UTC时间
|
|||
|
|
elapsed_recent = (now_utc - recent_created_time).total_seconds()
|
|||
|
|
time_remaining_recent = max(0, int(countdown_seconds - elapsed_recent))
|
|||
|
|
print(f"\nFor recently created chest:")
|
|||
|
|
print(f"Created time: {recent_created_time}")
|
|||
|
|
print(f"Elapsed seconds: {elapsed_recent}")
|
|||
|
|
print(f"Time remaining: {time_remaining_recent} seconds")
|