An accurate enough way is to use the millis() function. It will return the value in milliseconds since the start of the Arduino. If you start the Arduino at a specific time, you will be able to calculate the exact date and time.


Why not an external module?? An RTC such as the DS3231 in merely 5$ and it includes a temperature sensor for you!

Answer from Dat Ha on Stack Exchange
🌐
Circuit Basics
circuitbasics.com › using-an-arduino-ethernet-shield-for-timekeeping
How to Get the Date and Time on an Arduino
October 22, 2024 - To install the Time library, search and install the library “Time” by Michael Margolis from the IDE’s Library Manager. See Figure 2 below as a guide. Figure 3. Arduino IDE Library Manager · After installing the libraries into the IDE, use keyword #include to add them to our sketch. // Using An Arduino Ethernet Shield To Get Date and Time #include <SPI.h> // for communication with Ethernet Shield #include <TimeLib.h> // for update/display of time #include <Ethernet.h> // for communication with NTP Server via UDP
Discussions

Get date and time information from laptop
I am using the official Arduino Uno kit - which has a cable which attaches to the laptop USB. I have 2 questions: What code should i write (which will get executed on Arduino) to read current date and time from the laptop? What do i need to do on the laptop to send the current date and time ... More on forum.arduino.cc
🌐 forum.arduino.cc
9
0
December 26, 2015
Get current time in arduino?
one option is the set the time on bootup and periodically via your serial protocol, the time library has a Processing example for how to do this. another is to add an RTC chip. if you just want to know latency, send one byte from the PC, and reply back from the arduino and then then divide by 2 and that's your transfer time. you can also work it out pretty closely using the baud rate and some math. More on reddit.com
🌐 r/arduino
5
2
December 1, 2015
How to put date and time in arduino code
Hi, I have a LoRa P2P RFM96 set up. One is set as transmitter and the other as receiver. I modified a code that the LoRa receiver receives a data from the transmitter every 15 minutes by putting a delay function. And it worked. However I wanted to add the date and time that the receiver gets ... More on forum.arduino.cc
🌐 forum.arduino.cc
11
0
August 8, 2022
How to fetch time and date from computer's RTC?
Take a look at the CompileTime library . It compiles the current PC time into the program automatically when you compile and automatically adjusts for the upload time to the Arduino so that the PC and Arduino keep perfect time together. The hours, minutes, and seconds are kept current from there on the Arduino side without needing any communications with the PC and can be retrieved and used whenever your program need them. The time is reset to the compile time if the Arduino loses power or is reset of course but it's a great way to keep the PC and Arduino time in sync if you don't have an RTC module. Cheers! ripred More on reddit.com
🌐 r/arduino
33
1
November 19, 2023
🌐
GitHub
github.com › PaulStoffregen › Time
GitHub - PaulStoffregen/Time: Time library for Arduino · GitHub
Using the Arduino Library Manager, install "Time by Michael Margolis". The code is derived from the Playground DateTime library but is updated to provide an API that is more flexible and easier to use.
Starred by 1.3K users
Forked by 688 users
Languages   C++ 64.4% | C 35.6%
🌐
Arduino
playground.arduino.cc › Code › Time
Arduino Playground - Time
It allows a sketch to get the time and date as: second, minute, hour, day, month and year. It also provides time as a standard C time_t so elapsed times can be easily calculated and time values shared across different platforms. Update: newer versions of Time, TimeAlarms, and DS1307RTC are available, featuring more updates for newer version of the Arduino IDE and compatibility with Arduino Due. The code ...
🌐
Arduino Forum
forum.arduino.cc › projects › general guidance
Get date and time information from laptop - General Guidance - Arduino Forum
December 26, 2015 - Hi, I am a Arduino beginner. I am using Arduino Uno. I working on my first project for which I need to get current date and time from the laptop. I am using the official Arduino Uno kit - which has a cable which attache…
🌐
Arduino
docs.arduino.cc › language-reference › en › functions › time › millis
millis() | Arduino Documentation
Use the following function to get the exact time the board has been running the current program in milliseconds: ... This function does not admit parameters. This function returns the number of milliseconds passed since the program started. Data type: ... This example code prints on the serial port the number of milliseconds passed since the Arduino board started running the code itself.
🌐
Arduino
docs.arduino.cc › libraries › time
Time | Arduino Documentation
June 21, 2021 - Home / Programming / Library / Time · Timing · License unknown · V1.6.1 · Michael Margolis · 06/21/2021 · Paul Stoffregen · http://playground.arduino.cc/Code/Time/ Timekeeping functionality for Arduino · Date and Time functions, with provisions to synchronize to external time sources like GPS and NTP (Internet).
Find elsewhere
🌐
Reddit
reddit.com › r/arduino › get current time in arduino?
r/arduino on Reddit: Get current time in arduino?
December 1, 2015 -

Hello,

I want to measure the time that takes to transmit a package from arduino to a device connected to the computer. I've thought about taking the current time in arduino when I send the package and take the current time in the Java app that is running in the computer when it receives a packet and then calculate the difference. There is no problem to take the current time in the Java part, but in the arduino's one I don't know how to do it. I've tried the Time library but if I use the now() method I get the time since the code is running. For example I've a delay of 5 seconds in the setup() and then I call the now() method and it returns 5.

Anyone know how to get the current time or have any idea to calculate the transmision time between the two devices?

Thanks!

🌐
Random Nerd Tutorials
randomnerdtutorials.com › home › project › esp32 › getting date and time with esp32 on arduino ide (ntp client)
Getting Date and Time with ESP32 (NTP Client) | Random Nerd Tutorials
June 12, 2024 - We’ve just published an updated version of this article for the ESP32 (easier version without having to install libraries) https://randomnerdtutorials.com/esp32-date-time-ntp-client-server-arduino/ Regards, Sara Reply · Go to https://github.com/taranais/NTPClient and download the NTPClient library modified by taranais. Unzip and place the folder on C: \ Users \\ Documents \ Arduino \ libraries ... The code can be further improved by loading the retrieved(from NTP) into the local inbuilt RTC of the 8266 with the following code, but it is recommended to update from internet at least daily as the inbuilt RTC is not dead accurate(Depends on application).
🌐
Random Nerd Tutorials
randomnerdtutorials.com › home › project › esp32 › esp32 ntp client-server: get date and time (arduino ide)
ESP32 NTP Client-Server: Get Date and Time (Arduino IDE) | Random Nerd Tutorials
March 25, 2020 - After uploading the code, press the ESP32 “Enable” button, and you should get the date and time every second as shown in the following figure. In this tutorial you’ve learned how to get date and time from an NTP server using the ESP32 programmed with Arduino IDE.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
How to put date and time in arduino code - Programming - Arduino Forum
August 8, 2022 - Hi, I have a LoRa P2P RFM96 set up. One is set as transmitter and the other as receiver. I modified a code that the LoRa receiver receives a data from the transmitter every 15 minutes by putting a delay function. And it worked. However I wanted to add the date and time that the receiver gets ...
🌐
HackMD
hackmd.io › @ampheo › how-to-make-arduino-tell-the-time
How to make Arduino tell the time? - HackMD
October 9, 2025 - **Components Needed:** * [Arduino Uno](https://www.ampheo.com/product/a000046-25542493) + Ethernet Shield OR ESP8266/ESP32 board * Internet connection **Code Example (for ESP8266)** ``` cpp #include <ESP8266WiFi.h> #include <NTPClient.h> #include <WiFiUdp.h> // WiFi credentials const char *ssid = "YOUR_WIFI_SSID"; const char *password = "YOUR_WIFI_PASSWORD"; // Define NTP Client WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "pool.ntp.org", 0, 60000); // Offset 0, update every 60s void setup() { Serial.begin(115200); // Connect to WiFi WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNE
🌐
Random Nerd Tutorials
randomnerdtutorials.com › home › project › esp32 › get epoch/unix time with the esp32 (arduino)
Get Epoch/Unix Time with the ESP32 (Arduino) | Random Nerd Tutorials
February 16, 2021 - Learn how to request Epoch time or Unix time using the ESP32 board with Arduino IDE. Getting the epoch time can be useful to timestamp your readings, etc...
🌐
Arduino
arduino.cc › en › Tutorial › TimeCheck
Arduino
From beginner to Advanced: Traverse the Arduino Landscape with Confidence, Empowered by Tutorials Tailored to Sharpen Your Skills and Fuel Your Maker Spirit
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Code to display time - Programming - Arduino Forum
April 16, 2022 - Hello! I have a code to display seconds and minutes but can't work out the logic for hours. void countTime() { Time++; int seconds = Time`; secLsd = seconds; secMsd = seconds/10; int minutes = (Time/60)`; …
🌐
Arduino Forum
forum.arduino.cc › projects › programming
How to display current time in Hour Minute Second Millisecond format in arduino? - Programming - Arduino Forum
April 25, 2018 - Hello guys, how can I display current time in Arduino? I have tried using mills() but it only shows the date since reboot of the arduino in milliseconds, how do I get the current time in HH:MM:SS:Milliseconds? not the ti…
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Accessing the current date - Programming - Arduino Forum
March 18, 2025 - I've pieced together the following code that connects to an NTP and adjusts for my timezone... this (borrowed) code seems to be working just fine. Now, I'd like to access a function in my loop() that returns a String in the format "YYYY-MM-DD" of the current moment in time and I can't seem to get ...