20 lines
577 B
Python
20 lines
577 B
Python
|
|
from datetime import datetime
|
||
|
|
import time
|
||
|
|
|
||
|
|
# 获取当前时间
|
||
|
|
now = datetime.now()
|
||
|
|
utc_now = datetime.utcnow()
|
||
|
|
|
||
|
|
print(f"Local time: {now}")
|
||
|
|
print(f"UTC time: {utc_now}")
|
||
|
|
print(f"Timezone offset: {now.utcoffset()}")
|
||
|
|
|
||
|
|
# 测试时间差计算
|
||
|
|
test_time = datetime.fromisoformat("2025-12-14T19:00:00")
|
||
|
|
elapsed = (now - test_time).total_seconds()
|
||
|
|
print(f"Time elapsed since {test_time}: {elapsed} seconds")
|
||
|
|
|
||
|
|
# 测试60秒倒计时
|
||
|
|
countdown_seconds = 60
|
||
|
|
time_remaining = max(0, int(countdown_seconds - elapsed))
|
||
|
|
print(f"Time remaining for 60s countdown: {time_remaining} seconds")
|