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 - Save the sketch as Arduino-ethernet-time-tutorial.ino and upload it to your Arduino Uno. The Arduino Uno with Ethernet Shield is set to request the current time from the NTP server and display it to the serial monitor. So now, run our project by connecting the ethernet switch to your router via a LAN cable.
Discussions

How to get current date and time from Arduino Cloud
I am using an Arduino UNO Q and I want to timestamp a movement when detected with my Grove PIR motion sensor. I am sending the detection of the motion to the cloud, but I also want the exact time. The time sent is in 1970, it’s clear to me why this is. But how can I get the current date & time? More on forum.arduino.cc
🌐 forum.arduino.cc
4
0
November 26, 2025
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
Get date and time information from laptop
I am using the official Arduino ... current date and time from the laptop? What do i need to do on the laptop to send the current date and time to Arduino? I have researched this in the last few d...... More on forum.arduino.cc
🌐 forum.arduino.cc
9
0
December 26, 2015
current date and time
i'm able to interface and lcd and rtc to arduino severino now i just want to display current date and time on lcd nd save it on rtc i just don't know how to get the current date and time from pc More on forum.arduino.cc
🌐 forum.arduino.cc
11
0
April 29, 2009
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Accessing the current date - Programming - Arduino Forum
March 18, 2025 - I've pieced together the following ... 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 it right. When the date rolls from one day ......
🌐
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 Forum
forum.arduino.cc › forum 2005-2010 (read only) › software › syntax & programs
current date and time - Syntax & Programs - Arduino Forum
April 29, 2009 - i'm able to interface and lcd and rtc to arduino severino now i just want to display current date and time on lcd nd save it on rtc i just don't know how to get the current date and time from pc
Find elsewhere
🌐
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 ...
🌐
Arduino
playground.arduino.cc › Code › DateTime
Arduino Playground - DateTime
August 8, 2022 - For more info please look at this Forum Post · The playground is a publicly-editable wiki about Arduino. ... The DateTime library adds timekeeping capability to the Arduino without requiring external hardware. It allows a sketch to get the current second, minute, hour, day, month and year.
🌐
Stack Overflow
stackoverflow.com › questions › 35923471 › get-current-time-in-arduino-1-6-6
Get current time in arduino 1.6.6 - Stack Overflow
You can get one with internal or external crystal, with or without battery to keep the time... They usually interface to the microcontroller through a I2C (or SPI) interface. You just set the time once (like you do for any clock) and it keeps ...
Top answer
1 of 1
4

An example how to use NTPClient is available at the projects github

#include <NTPClient.h>
// change next line to use with another board/shield
#include <ESP8266WiFi.h>
//#include <WiFi.h> // for WiFi shield
//#include <WiFi101.h> // for WiFi 101 shield or MKR1000
#include <WiFiUdp.h>

const char *ssid     = "<SSID>";
const char *password = "<PASSWORD>";

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);

void setup(){
  Serial.begin(115200);

  WiFi.begin(ssid, password);

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }

  timeClient.begin();
}

void loop() {
  timeClient.update();

  Serial.println(timeClient.getFormattedTime());

  delay(1000);
}

Form what I found TimeRTC requires an external device called DS1307RTC to keep track of the time as shown in video here and with it we should be able to get the real time as seen in github example

#include <TimeLib.h>
#include <Wire.h>
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

void setup()  {
  Serial.begin(9600);
  while (!Serial) ; // wait until Arduino Serial Monitor opens
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet) 
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");      
}

void loop()
{
  if (timeStatus() == timeSet) {
    digitalClockDisplay();
  } else {
    Serial.println("The time has not been set.  Please run the Time");
    Serial.println("TimeRTCSet example, or DS1307RTC SetTime example.");
    Serial.println();
    delay(4000);
  }
  delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

If what I understand from your code you are actually not using any RTP or NTP. You are only creating a Time object with no values and you read it default values.

Check some more examples here

🌐
Shinyu
shinyu.org › en › arduino › dates-and-times › getting-the-current-date
Arduino: Getting the current date
March 14, 2024 - Chapter 7. Dates and Times ... Arduino itself doesn’t have a built-in method to directly fetch the current date, as it lacks a real-time clock (RTC).
🌐
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!

🌐
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…
🌐
Quora
quora.com › How-can-I-get-the-current-time-on-arduino
How to get the current time on arduino - Quora
Answer (1 of 4): There are many RTC ICs available. Some communicate using i2c and some using SPI. One of the most common rtc for arduino is ds1307 from dallas/maxim. It communicates via i2c and has a fully functional library in arduino.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Get the current date - Programming - Arduino Forum
November 29, 2012 - Hello, At the moment my project is getting the current time (using the example included with the Arduino software) would it be possible to modify that code to also get the date? I only need the day and the month. I don'…
🌐
Circuit Basics
circuitbasics.com › how-to-use-a-real-time-clock-module-with-the-arduino
How to Use a Real-time Clock Module with the Arduino
October 21, 2024 - An RTC is a very popular and accurate source of time and date in an embedded system like an Arduino because it has low power consumption. If you want to learn how to communicate with an internet time server to get the current time and date, please read How to Keep Track of the Date and Time on an Arduino.
🌐
HackMD
hackmd.io › @ampheo › how-to-make-arduino-tell-the-time
How to make Arduino tell the time? - HackMD
October 9, 2025 - // This sets the RTC to the date & time this sketch was compiled // rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Alternatively, you can set it to a specific date & time: // rtc.adjust(DateTime(2024, 1, 15, 14, 30, 0)); // (Year, Month, Day, Hour, Minute, Second) } void loop() { DateTime now = rtc.now(); // Get the current time from RTC // Print to Serial Monitor Serial.print("Date: "); Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.day(), DEC); Serial.print(" ("); Serial.print(daysOfTheWeek[now.dayOfTheWeek()]); Seria
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Get Date and Time Without RTC Shields - Programming - Arduino Forum
August 4, 2016 - I'm trying to get the Arduino Uno or Mega to print the date and time onto the serial monitor. All the tutorial requires a RTC hardware add-on such as an adafruit data logger. Is there a way to do this with coding alone?
🌐
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 - The easiest way to get date and time from an NTP server is using an NTP Client library. For that we’ll be using the NTP Client library forked by Taranais. Follow the next steps to install this library in your Arduino IDE: