import urequests
import utime
# 从网络获取当前时间
def get_current_time():
try:
# 向时间服务器发送请求
response = urequests.get("https://worldtimeapi.org/api/timezone/Asia/Shanghai")
# 解析响应中的时间数据
time_data = response.json()
#print(time_data)
# 获取时间戳(以秒为单位)
timestamp = time_data["datetime"]
# 关闭网络连接
response.close()
# 返回时间戳
return timestamp
except Exception as e:
print("Error:", e)
return None
t=get_current_time()
print(t)