Getting Time Stamp on Arduino MKR Zero

Hi everyone, I write a project on Arduino MKR Zero and I want to include a timestamp.
I am using the RTCZero library and there is an example called SimpleRTC. The final project will not have network connectivity so I can't use any NTP server for date and time acquisition.

My problem with the SimpleRTC example is that I have to set manually the date and time and therefore each time the RTC stays out of power I have to re-configure manually the data and time. Is there any way to take the data and time from my machine (like the DC3221 module) instead of configuring manually?

#include <RTCZero.h>

/* Create an rtc object */
RTCZero rtc;

/* Change these values to set the current initial time */
const byte seconds = 0;
const byte minutes = 0;
const byte hours = 16;

/* Change these values to set the current initial date */
const byte day = 15;
const byte month = 6;
const byte year = 15;

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

  rtc.begin(); // initialize RTC

  // Set the time
  rtc.setHours(hours);
  rtc.setMinutes(minutes);
  rtc.setSeconds(seconds);

  // Set the date
  rtc.setDay(day);
  rtc.setMonth(month);
  rtc.setYear(year);

  // you can use also
  //rtc.setTime(hours, minutes, seconds);
  //rtc.setDate(day, month, year);
}

void loop()
{
  // Print date...
  print2digits(rtc.getDay());
  Serial.print("/");
  print2digits(rtc.getMonth());
  Serial.print("/");
  print2digits(rtc.getYear());
  Serial.print(" ");

  // ...and time
  print2digits(rtc.getHours());
  Serial.print(":");
  print2digits(rtc.getMinutes());
  Serial.print(":");
  print2digits(rtc.getSeconds());

  Serial.println();

  delay(1000);
}



void print2digits(int number) {
  if (number < 10) {
    Serial.print("0"); // print a 0 before if the number is < than 10
  }
  Serial.print(number);
}

Connect the board to a battery to let it keep the time while the main processor sleeps.

I know that this is a partial solution and I am going to include a battery. But it is more convinient for me the date and time to be updated from the local mashine. Also, everytime I have to build and upload the sketch I must manualy re-configure the date and time..

Is it suggested to set the RTC clock with the compile-time using the macros TIME and DATE ? I know that some parsing is required but this is not the case.. The compilation time matches the computer's time, isn't it?

But it is more convinient for me the date and time to be updated from the local mashine.

What's the "local machine"? If you have the battery applied you shouldn't have to update time and date for months.

Is it suggested to set the RTC clock with the compile-time using the macros TIME and DATE ? I know that some parsing is required but this is not the case.. The compilation time matches the computer's time, isn't it?

Bad idea, every time you start that sketch, time of the compiler run will be set again.

You might use it to set the time once and upload another sketch immediately after that. I prefer to set the time by a serial interface but that's up to you.

[/quote]

pylon:
What's the "local machine"? You might use it to set the time once and upload another sketch immediately after that.

That's exactly what I am going to. Local machine I mean the computer.

So all problems resolved?

Yes so far so good, it works fine with these macros. There is a bit of offset (around 6 sec) but I am happy with that..