# \[BASIC] 008 TIME GET DATETIME (วันเวลา)

สวัสดีครับ สำหรับหัวข้อบทเรียนพื้นฐานบนบอร์ด HONEYLemon ที่ใช้งานผ่าน arduino library โดยเป็นการใช้งานเกี่ยวกับการอ่านข้อมูล Date Time ซึ่งจะทำการดึงข้อมูลจากอินเตอร์เน็ตผ่าน WiFi

อ่านข้อมูลเพิ่มเติมสำหรับการเชื่อมต่อ WiFi

{% content-ref url="/pages/-MA5r7zqnmaErAORBQ3y" %}
[\[BASIC\] 007 WiFi SETUP WiFi (ต่อเน็ต)](/blogs/basic/basic-007-wifi-setup-wifi.md)
{% endcontent-ref %}

เมื่อเชื่อมต่อ WiFi ได้แล้วจากบทความข้างต้น ระบบก็จะทำการ sync เวลาให้อัตโนมัติ คราวนี้ก็ทำการดึงข้อมูลมาได้เลย

คำสั่งที่เกี่ยวข้อง

```
lemon.getDateTime();
```

ซึ่งจะได้ข้อมูลแสดงค่าวันเวลาตามรูปแบบ Year-Month-Day T Hour:Minute:Second

เช่น 2020-01-16T19:29:39\
วันที่ 16 เดือน 01 ปี 2020\
เวลา 19 นาฬิกา 29 นาที 39 วินาที

**ตัวอย่าง source code**

```
/*
    Basic : การเขียนโปรแกรมกับอ่านค่าวันที่จากอินเตอร์เน็ตบนบอร์ดไมโครคอนโทรลเลอร์ HONEYLemon
*/
#include <HONEYLemon.h>

#define WIFI_SSID  "WiFi_Name"      // ตั้งค่าชื่อ WiFi
#define WIFI_PASS  "WiFi_Password"  // ตั้งค่ารหัสผ่าน WiFi

void setup()
{
    lemon.begin();          // เรียกใช้งานฟังก์ชั่นเริ่มต้นของบอร์ด HONEYLemon

    Serial.begin(115200);   // เรียกใช้งาน Serial
    lemon.debug(Serial);    // ขอดู debug ของบอร์ด HONEYLemon ผ่าน Serial

    // เรียกการใช้งานการตั้งค่า WiFi
    lemon.setupWiFi(WIFI_SSID, WIFI_PASS);
}

void loop()
{
    /*
        getDateTime()   // อ่านค่า ปี-เดือน-วัน และ ชั่วโมง:นาที:วินาที Year-Month-Day T Hour:Minute:Second (String)
    */
    Serial.println( lemon.getDateTime() );  // อ่านค่าพร้อมแสดงผลวันเวลา Year-Month-Day T Hour:Minute:Second
    delay(1000);    // รอ 1000 มิลลิวินาที (1 วินาที)
}
```


---

# Agent Instructions: 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:

```
GET https://lemon.honey.co.th/blogs/basic/basic-008-time-get-datetime.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
