{"id":95190,"date":"2020-03-25T15:22:19","date_gmt":"2020-03-25T15:22:19","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=95190"},"modified":"2020-11-26T16:45:16","modified_gmt":"2020-11-26T16:45:16","slug":"esp8266-nodemcu-date-time-ntp-client-server-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-date-time-ntp-client-server-arduino\/","title":{"rendered":"ESP8266 NodeMCU NTP Client-Server: Get Date and Time (Arduino IDE)"},"content":{"rendered":"\n<p>In this tutorial you\u2019ll learn how to get date and time from an NTP server using the ESP8266 NodeMCU with Arduino IDE. Getting date and time is useful in data logging projects to timestamp readings. To get time from an NTP Server, the <a href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"ESP8266 (opens in a new tab)\">ESP8266<\/a> needs to have an Internet connection and you don\u2019t need additional hardware (like an RTC clock).<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-NodeMCU-Get-Date-Day-Time-Hour-Minute-Arduino-IDE-NTP-Client-Server.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU NTP Client-Server: Get Date and Time Arduino IDE\" class=\"wp-image-95242\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-NodeMCU-Get-Date-Day-Time-Hour-Minute-Arduino-IDE-NTP-Client-Server.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-NodeMCU-Get-Date-Day-Time-Hour-Minute-Arduino-IDE-NTP-Client-Server.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-NodeMCU-Get-Date-Day-Time-Hour-Minute-Arduino-IDE-NTP-Client-Server.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-NodeMCU-Get-Date-Day-Time-Hour-Minute-Arduino-IDE-NTP-Client-Server.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p>Before proceeding make sure you have the ESP8266 board installed in Arduino IDE:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/how-to-install-esp8266-board-arduino-ide\/\">Installing ESP8266 Board in Arduino IDE (Windows, Mac OS X, Linux)<\/a><\/li><\/ul>\n\n\n\n<p><strong>Recommended:<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/esp32-date-time-ntp-client-server-arduino\/\">Get Date and Time with ESP32 NTP Client-Server<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">NTP (Network Time Protocol)<\/h2>\n\n\n\n<p>NTP stands for Network Time Protocol and it is a networking protocol for clock synchronization between computer systems. In other words, it is used to synchronize computer clock times in a network.<\/p>\n\n\n\n<p>There are NTP servers like <em>pool.ntp.org<\/em> that anyone can use to request time as a client. In this case, the ESP8266 is an NTP Client that requests time from an NTP Server (<em>pool.ntp.org<\/em>).<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"395\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-NTP-Client-Server.png?resize=750%2C395&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"NTP Network Time Protocol ESP8266 NodeMCU Request time and date\" class=\"wp-image-95213\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-NTP-Client-Server.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-NTP-Client-Server.png?resize=300%2C158&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Installing the NTPClient Library<\/h2>\n\n\n\n<p>We\u2019ll use the NTPClient library to get time. In your Arduino IDE, go to <strong>Sketch <\/strong>&gt; <strong>Library <\/strong>&gt; <strong>Manage Libraries<\/strong>. The Library Manager should open.<\/p>\n\n\n\n<p>Search for <strong>NTPClient <\/strong>and install the library by Fabrice Weinber as shown in the following image.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"786\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-install-NTP-Client-Library.png?resize=786%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install NTPClient Library ESP8266 NodeMCU\" class=\"wp-image-95192\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-install-NTP-Client-Library.png?w=786&amp;quality=100&amp;strip=all&amp;ssl=1 786w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-install-NTP-Client-Library.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-install-NTP-Client-Library.png?resize=768%2C433&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">NTPClient Library Time Functions<\/h2>\n\n\n\n<p>The NTPClient Library comes with the following functions to return time:<\/p>\n\n\n\n<p><span class=\"rnthl rntliteral\">getDay()<\/span> &#8211; returns an int number that corresponds to the the week day (0 to 6) starting on Sunday;<\/p>\n\n\n\n<p><span class=\"rnthl rntliteral\">getHours()<\/span> &#8211; returns an int number with the current hour (0 to 23) in 24 hour format;<\/p>\n\n\n\n<p><span class=\"rnthl rntliteral\">getMinutes()<\/span> &#8211; returns an int number with the current minutes (0 to 59);<\/p>\n\n\n\n<p><span class=\"rnthl rntliteral\">getSeconds()<\/span> &#8211; returns an int number with the current second; <\/p>\n\n\n\n<p><span class=\"rnthl rntliteral\">getEpochTime()<\/span> &#8211; returns an unsigned long with the epoch time (number of seconds that have elapsed since January 1, 1970 (midnight GMT);<\/p>\n\n\n\n<p><span class=\"rnthl rntliteral\">getFormattedTime()<\/span> &#8211; returns a String with the time formatted like HH:MM:SS;<\/p>\n\n\n\n<p>This library doesn\u2019t come with functions to return the date, but we\u2019ll show you in the code how to get the date (day, month and year).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ESP8266 NodeMCU Code<\/h2>\n\n\n\n<p>The following code connects the ESP8266 to an NTP Server (<em>pool.ntp.org<\/em>) to request date and time. It displays the current date and time in several formats in the Serial Monitor.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp8266-nodemcu-date-time-ntp-client-server-arduino\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files.\n  \n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n*\/\n\n#include &lt;ESP8266WiFi.h&gt;\n#include &lt;NTPClient.h&gt;\n#include &lt;WiFiUdp.h&gt;\n\n\/\/ Replace with your network credentials\nconst char *ssid     = &quot;REPLACE_WITH_YOUR_SSID&quot;;\nconst char *password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\n\n\/\/ Define NTP Client to get time\nWiFiUDP ntpUDP;\nNTPClient timeClient(ntpUDP, &quot;pool.ntp.org&quot;);\n\n\/\/Week Days\nString weekDays[7]={&quot;Sunday&quot;, &quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;, &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot;};\n\n\/\/Month names\nString months[12]={&quot;January&quot;, &quot;February&quot;, &quot;March&quot;, &quot;April&quot;, &quot;May&quot;, &quot;June&quot;, &quot;July&quot;, &quot;August&quot;, &quot;September&quot;, &quot;October&quot;, &quot;November&quot;, &quot;December&quot;};\n\nvoid setup() {\n  \/\/ Initialize Serial Monitor\n  Serial.begin(115200);\n  \n  \/\/ Connect to Wi-Fi\n  Serial.print(&quot;Connecting to &quot;);\n  Serial.println(ssid);\n  WiFi.begin(ssid, password);\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(&quot;.&quot;);\n  }\n\n\/\/ Initialize a NTPClient to get time\n  timeClient.begin();\n  \/\/ Set offset time in seconds to adjust for your timezone, for example:\n  \/\/ GMT +1 = 3600\n  \/\/ GMT +8 = 28800\n  \/\/ GMT -1 = -3600\n  \/\/ GMT 0 = 0\n  timeClient.setTimeOffset(0);\n}\n\nvoid loop() {\n  timeClient.update();\n\n  time_t epochTime = timeClient.getEpochTime();\n  Serial.print(&quot;Epoch Time: &quot;);\n  Serial.println(epochTime);\n  \n  String formattedTime = timeClient.getFormattedTime();\n  Serial.print(&quot;Formatted Time: &quot;);\n  Serial.println(formattedTime);  \n\n  int currentHour = timeClient.getHours();\n  Serial.print(&quot;Hour: &quot;);\n  Serial.println(currentHour);  \n\n  int currentMinute = timeClient.getMinutes();\n  Serial.print(&quot;Minutes: &quot;);\n  Serial.println(currentMinute); \n   \n  int currentSecond = timeClient.getSeconds();\n  Serial.print(&quot;Seconds: &quot;);\n  Serial.println(currentSecond);  \n\n  String weekDay = weekDays[timeClient.getDay()];\n  Serial.print(&quot;Week Day: &quot;);\n  Serial.println(weekDay);    \n\n  \/\/Get a time structure\n  struct tm *ptm = gmtime ((time_t *)&amp;epochTime); \n\n  int monthDay = ptm-&gt;tm_mday;\n  Serial.print(&quot;Month day: &quot;);\n  Serial.println(monthDay);\n\n  int currentMonth = ptm-&gt;tm_mon+1;\n  Serial.print(&quot;Month: &quot;);\n  Serial.println(currentMonth);\n\n  String currentMonthName = months[currentMonth-1];\n  Serial.print(&quot;Month name: &quot;);\n  Serial.println(currentMonthName);\n\n  int currentYear = ptm-&gt;tm_year+1900;\n  Serial.print(&quot;Year: &quot;);\n  Serial.println(currentYear);\n\n  \/\/Print complete date:\n  String currentDate = String(currentYear) + &quot;-&quot; + String(currentMonth) + &quot;-&quot; + String(monthDay);\n  Serial.print(&quot;Current date: &quot;);\n  Serial.println(currentDate);\n\n  Serial.println(&quot;&quot;);\n\n  delay(2000);\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266\/ESP8266_Date_Time.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Code Works<\/h2>\n\n\n\n<p>First, include the necessary libraries.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;ESP8266WiFi.h>\n#include &lt;NTPClient.h>\n#include &lt;WiFiUdp.h><\/code><\/pre>\n\n\n\n<p>Insert your network credentials in the following variables so that the ESP8266 can connect to your router to have access to the internet to request date and time from the NTP server.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char *ssid     = \"REPLACE_WITH_YOUR_SSID\";\nconst char *password = \"REPLACE_WITH_YOUR_PASSWORD\";<\/code><\/pre>\n\n\n\n<p>Define an NTP client to get date and time.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>WiFiUDP ntpUDP;\nNTPClient timeClient(ntpUDP, \"pool.ntp.org\");<\/code><\/pre>\n\n\n\n<p>We\u2019ll request the time from <em>pool.ntp.org<\/em>, which is a cluster of times servers that anyone can use to request the time.<\/p>\n\n\n\n<p>Next, we create two arrays to hold the days of the week and the month names.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/Week Days\nString weekDays&#091;7]={\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"};\n\n\/\/Month names\nString months&#091;12]={\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"};<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">setup()<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor to display the information.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<p>Next, connect the ESP8266 to the internet.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Connect to Wi-Fi\nSerial.print(\"Connecting to \");\nSerial.println(ssid);\nWiFi.begin(ssid, password);\nwhile (WiFi.status() != WL_CONNECTED) {\n  delay(500);\n  Serial.print(\".\");\n}<\/code><\/pre>\n\n\n\n<p>Initialize the NTPClient.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>timeClient.begin();<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Set Timezone<\/h4>\n\n\n\n<p>You can use the <span class=\"rnthl rntliteral\">setTimeOffset()<\/span> method to adjust the time for your timezone in seconds.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>timeClient.setTimeOffset(3600);<\/code><\/pre>\n\n\n\n<p> Here are some examples for different timezones:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>GMT +1 = 3600<\/li><li>GMT +8 = 28800<\/li><li>GMT -1 = -3600<\/li><li>GMT 0 = 0<\/li><\/ul>\n\n\n\n<p>We live in Portugal, so we don\u2019t need to adjust the time.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>timeClient.setTimeOffset(0);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">loop()<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, call the <span class=\"rnthl rntliteral\">update()<\/span> function to get the current date and time from the NTP server.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>timeClient.update();<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Get Time<\/h4>\n\n\n\n<p>Then, we can use the functions provided by the library to get time. For example, to get the epoch time:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>unsigned long epochTime = timeClient.getEpochTime();\nSerial.print(\"Epoch Time: \");\nSerial.println(epochTime);<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">getFormattedTime()<\/span> function returns the time in HH:MM:SS format.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String formattedTime = timeClient.getFormattedTime();\nSerial.print(\"Formatted Time: \");\nSerial.println(formattedTime);  <\/code><\/pre>\n\n\n\n<p>You can get the hours, minutes or seconds separately using the <span class=\"rnthl rntliteral\">getHours()<\/span>, <span class=\"rnthl rntliteral\">getMinutes()<\/span> and <span class=\"rnthl rntliteral\">getSeconds()<\/span> functions as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int currentHour = timeClient.getHours();\nSerial.print(\"Hour: \");\nSerial.println(currentHour);  \n\nint currentMinute = timeClient.getMinutes();\nSerial.print(\"Minutes: \");\nSerial.println(currentMinute); \n   \nint currentSecond = timeClient.getSeconds();\nSerial.print(\"Seconds: \");\nSerial.println(currentSecond);  <\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Get Date<\/h4>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">getDay()<\/span> function returns a number from 0 to 6, in which 0 corresponds to Sunday and 6 to Saturday. So, we can access the week day name from the array we\u2019ve created previously as follows<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String weekDay = weekDays&#091;timeClient.getDay()];\nSerial.print(\"Week Day: \");\nSerial.println(weekDay);  <\/code><\/pre>\n\n\n\n<p>The NTP Client doesn\u2019t come with functions to get the date. So, we need to create a time structure (<span class=\"rnthl rntliteral\">struct tm<\/span>) and then, access its elements to get information about the date.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>struct tm *ptm = gmtime ((time_t *)&amp;epochTime);<\/code><\/pre>\n\n\n\n<p>The time structure contains the following elements:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span class=\"rnthl rntliteral\">tm_sec<\/span>: seconds after the minute;<\/li><li><span class=\"rnthl rntliteral\">tm_min<\/span>: minutes after the hour;<\/li><li><span class=\"rnthl rntliteral\">tm_hour<\/span>: hours since midnight;<\/li><li><span class=\"rnthl rntliteral\">tm_mday<\/span>: day of the month;<\/li><li><span class=\"rnthl rntliteral\">tm_year<\/span>: years since 1900;<\/li><li><span class=\"rnthl rntliteral\">tm_wday<\/span>: days since Sunday;<\/li><li><span class=\"rnthl rntliteral\">tm_yday<\/span>: days since January 1;<\/li><li><span class=\"rnthl rntliteral\">tm_isdst<\/span>: Daylight Saving Time flag;<\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"http:\/\/www.cplusplus.com\/reference\/ctime\/tm\/\" target=\"_blank\">tm structure documentation<\/a>.<\/li><\/ul>\n\n\n\n<p>The following lines get the day of the month as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int monthDay = ptm->tm_mday;\nSerial.print(\"Month day: \");\nSerial.println(monthDay);<\/code><\/pre>\n\n\n\n<p>To get the other elements, you use a similar approach. For example, for the month:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int currentMonth = ptm->tm_mon+1;\nSerial.print(\"Month: \");\nSerial.println(currentMonth);<\/code><\/pre>\n\n\n\n<p>Because the tm_mday starts at 0, we add 1 to the month so that January corresponds to 1, February to 2, and so on.<\/p>\n\n\n\n<p>Then, we can get the name of the month using the <span class=\"rnthl rntliteral\">months<\/span> array we\u2019ve created previously. The arrays numbering starts at 0, that\u2019s why we subtract 1.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String currentMonthName = months&#091;currentMonth-1];\nSerial.print(\"Month name: \");\nSerial.println(currentMonthName);<\/code><\/pre>\n\n\n\n<p>To get the year, we need to add 1900 because the <span class=\"rnthl rntliteral\">tm_year<\/span> saves the number of years after 1900.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int currentYear = ptm->tm_year+1900;\nSerial.print(\"Year: \");\nSerial.println(currentYear);<\/code><\/pre>\n\n\n\n<p>Finally, we create a String called <span class=\"rnthl rntliteral\">currentDate<\/span> that holds the current date in the YYYY-MM-DD format.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code> String currentDate = String(currentYear) + \"-\" + String(currentMonth) + \"-\" + String(monthDay);\n Serial.print(\"Current date: \");\n Serial.println(currentDate);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>After inserting your network credentials and modifying the variables to adjust the time to your timezone, test the example.<\/p>\n\n\n\n<p>Upload the code your ESP8266 board. Make sure you have the right board and COM port selected.<\/p>\n\n\n\n<p>Open the Serial Monitor at a baud rate of 115200. The date and time should be displayed in several formats as shown below.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"725\" height=\"445\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266_NTP_date_time_Serial_Monitor.png?resize=725%2C445&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU Get Date and Time NTP Client-Server Arduino IDE Serial Monitor demonstration\" class=\"wp-image-95191\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266_NTP_date_time_Serial_Monitor.png?w=725&amp;quality=100&amp;strip=all&amp;ssl=1 725w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266_NTP_date_time_Serial_Monitor.png?resize=300%2C184&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial you\u2019ve learned how to get date and time from an NTP server using the ESP8266. This is specially useful for data logging projects that have access to the internet.<\/p>\n\n\n\n<p>If you don\u2019t have access to the internet, you can use an <a href=\"https:\/\/makeradvisor.com\/tools\/real-time-clock-module-ds1307\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">RTC module like the DS1307<\/a>.<\/p>\n\n\n\n<p>If you want to learn more about the ESP8266, check our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\">Home Automation using ESP8266<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/micropython-programming-with-esp32-and-esp8266\/\">MicroPython Programming with ESP32 and ESP8266<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp8266\/\">More ESP8266 projects\u2026<\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial you\u2019ll learn how to get date and time from an NTP server using the ESP8266 NodeMCU with Arduino IDE. Getting date and time is useful in data &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP8266 NodeMCU NTP Client-Server: Get Date and Time (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-date-time-ntp-client-server-arduino\/#more-95190\" aria-label=\"Read more about ESP8266 NodeMCU NTP Client-Server: Get Date and Time (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":95242,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[214,265,246,240,300,264],"tags":[],"class_list":["post-95190","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp8266","category-esp8266-project","category-esp8266-arduino-ide","category-esp8266-projects","category-0-esp8266","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/03\/ESP8266-NodeMCU-Get-Date-Day-Time-Hour-Minute-Arduino-IDE-NTP-Client-Server.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/95190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=95190"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/95190\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/95242"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=95190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=95190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=95190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}