> For the complete documentation index, see [llms.txt](https://sharinghub.kittenbot.hk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sharinghub.kittenbot.hk/mcu/futureboard/micropython/api8.md).

# 未來版MicroPython編程8：網絡時間

### 導入未來板庫

需要先導入未來板的庫才可以使用未來板的硬件。

```
from future import *
```

### 08: 網絡時間

### 導入網絡時間庫

```
from machine import RTC
import ntptime
```

#### 1. 初始化時鐘

```
rtc = RTC()
```

#### 2. 同步網絡時間

```
ntptime.settime(zone=8)
```

zone為時區，默認為8(北京上海香港時間)。

#### 3. 獲取時間

```
rtc.datetime()
```

返回一組列表，格式為年、月、日、星期、時、分、微秒。

#### 網絡時間範例程式

```
#/bin/python
from future import *

import ntptime

from machine import RTC
rtc = RTC()

from time import sleep

wifi.connect(str("wifi"), "password")
ntptime.settime(int(8))
screen.sync = 0
while True:
  screen.fill((0, 0, 0))
  screen.text("Time:",5,10,2,(0, 119, 255))
  screen.text(str(rtc.datetime()[int(4)])+str(str(":")+str(rtc.datetime()[int(5)])),5,40,3,(0, 119, 255))
  screen.refresh()
  sleep(1)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sharinghub.kittenbot.hk/mcu/futureboard/micropython/api8.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
