How to display current time in Hour Minute Second Millisecond format in arduino?

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 time after the last reboot

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html

You will need a RealTimeClock ,RTC, to keep the real time for you so that when you boot the Arduino it can read the RTC and display it.

What model Arduino are you using?

These links may help;

Tom... :slight_smile:

You need an RTC that retains timekeeping between restarts.
e.g. DS1307 or DS3231 + battery
The Arduino has no awareness of where the sun, planets and moon are positioned.

Going upscale a bit, you could use NTP or cellular time.

First off, to get real time, you need an RTC.
A DS3231 is a good choice.

You should probably review this link.
https://playground.arduino.cc/Code/Time

Library from here:

Try 'TimeSerial' example
Use T1357041600 to set the time, change as needed.

You would need to set the time for the above to work.

But you really need to look at an RTC if you want things to work over a power up/fail condition.

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html

You will need a RealTimeClock ,RTC, to keep the real time for you so that when you boot the Arduino it can read the RTC and display it.

What model Arduino are you using?

These links may help;
RTC Real Time Clock Module Quickstart Guide | Freetronics
Arduino and DS3231 Real Time Clock Tutorial - How To Mechatronics

Tom... :slight_smile:

hello sir, sorry for the bad posting. I am using arduino UNO, how about the log command in gobetwino? I can save the time stamp in Month/Date/Year Hour:Minute:Second format using the log command in gobetwino but how do i add the milliseconds?

i think here's the code

void readSerialString (char *strArray,long timeOut) 
{
   long startTime=millis();
   int i;

   while (!Serial.available()) {
      if (millis()-startTime >= timeOut) {
         return;
      }
   }
   while (Serial.available() && i < serInLen) {
      strArray[i] = Serial.read();
      i++;
   }
}

larryd:
First off, to get real time, you need an RTC.
A DS3231 is a good choice.

You should probably review this link.
Arduino Playground - HomePage

Library from here:
Time/examples at master · PaulStoffregen/Time · GitHub

Try 'TimeSerial' example
Use T1357041600 to set the time, change as needed.

You would need to set the time for the above to work.
https://www.epochconverter.com/

But you really need to look at an RTC if you want things to work over a power up/fail condition.

is there no other way to do that without a RTC?

Hi,

I can save the time stamp in Month/Date/Year Hour:Minute:Second format using the log command in gobetwino but how do i add the milliseconds?

The manual for Gobetwino,says that it only works to seconds, why do you need milliseconds?

https://playground.arduino.cc/Interfacing/GoBetwino

Tom.. :slight_smile:

TomGeorge:
Hi,The manual for Gobetwino,says that it only works to seconds, why do you need milliseconds?

Arduino Playground - HomePage

Tom.. :slight_smile:

TomGeorge:
Hi,The manual for Gobetwino,says that it only works to seconds, why do you need milliseconds?

Arduino Playground - HomePage

Tom.. :slight_smile:

I need milliseconds because the time I am saving is the message sent time which needs milliseconds because I am using gsm in arduino to send it. And the delay of the messages must be Less than 1 second.

abujuguluy:
is there no other way to do that without a RTC?

You can use the Time library for hr min sec etc. but not ms.

Don’t know of a way to get what you want.

because I am using gsm in arduino to send it. And the delay of the messages must be Less than 1 second.

Any messages sent over the cellular network are nowhere near millisecond accuracy.
I’d be happy if it was under 1 second in most cases.
So many places where buffering and retries will occur that are out of your control.