Difference in time between IDE and Arduino Create

If I use the following to set the time on an Arduino via the IDE (1.8.9), my RTC module is set to the time of my computer.

RTC.adjust(DateTime(DATE, TIME));

But if I upload exactly the same code via the Arduino Create Web IDE on Chrome the time is set two hours earlier than that of my computer.

Why is this?

steveinaustria:
If I use the following to set the time on an Arduino via the IDE (1.8.9), my RTC module is set to the time of my computer.

RTC.adjust(DateTime(DATE, TIME));

But if I upload exactly the same code via the Arduino Create Web IDE on Chrome the time is set two hours earlier than that of my computer.

Why is this?

__DATE__ and __TIME__ are macros that stand for date and time on the machine that runs the compiler.

When you compile locally in Arduino IDE, it is the time on your computer.

When you compile in an online Arduino Create Web IDE, it is the time on a remote server that ran the compiler for you.

Is the Web IDE server always the same one? Basically, if the time is always going to be two hours different from my local time I can easily account for that in my code. But if it is not a consistent diffence it will be much more difficult to calculate and compensate for.

Who knows? Maybe it is, maybe it isn't. The whole point of doing things "in the cloud" (annoying term) is that you are not supposed to know or care where you processing requests are handled.

What I don't completely understand is the value of this __DATE__ and __TIME__ technique for you. It hardcodes the compilation time into your program. This hardcoded time will only make sense as RTC if you run your program immediately after compilation. If you restart your Arduino, say, five hours later, this time value will not make much sense anymore.

It is probably better than nothing. But you seem to care about having the proper time value to initialize you RTC.

"If you restart your Arduino, say, five hours later, this time value will not make much sense anymore." It will keep the value because the Arduino has an RTC attached.

I use my Arduino for lots of tasks, one being a clock for my grandkids which uses different coloured leds to show the time. When the grandkids come to stay I set up the clock, and for that I need the real time where we actually are and not the time where some random server is. The RTC keeps the time for the whole of their visit of two or three days, and then I dismantle the setup and use the Arduino for other things.

steveinaustria:
"If you restart your Arduino, say, five hours later, this time value will not make much sense anymore." It will keep the value because the Arduino has an RTC attached.

Yes, but how do you make sure that the above RTC.adjust(DateTime(__DATE__, __TIME__)); line is executed only once after each compilation and NOT executed during later restarts?

If you call that adjust every time your Arduino starts, it will simply override your current RTC time with the hardcoded compilation time, thus completely defeating the purpose of having a RTC clock. If you compiled your program on January 1, 2019, every time you start your Arduino it will bash January 1, 2019 into your RTC clock.

I use my Arduino for lots of tasks, one being a clock for my grandkids which uses different coloured leds to show the time. When the grandkids come to stay I set up the clock, and for that I need the real time where we actually are and not the time where some random server is. The RTC keeps the time for the whole of their visit of two or three days, and then I dismantle the setup and use the Arduino for other things.

That's great, but what if you will simply need to power off/power on the clock? In this case a RTC clock with battery backup is actually quite useful, since it will continue to keep proper time while your Arduino is powered off/restarting.

Meanwhile, it appears that when you power up your Arduino, instead of reading proper time from the RTC clock, you simply do RTC.adjust(DateTime(__DATE__, __TIME__));. I.e. you ignore the proper time and instead override it with some inaccurate values from the past.

Again, were in your code is that RTC.adjust(DateTime(__DATE__, __TIME__)); located?

Those macros are used in the simple examples which come with the RTC library. They are intended to only be examples to get you started quickly. They should not be used in real applications.

The correct usage is either of the two methods below:

  1. Once in the life of the RTC battery, compile and upload the example time-setter (with any hardcoded offsets required).

  2. Use a proper time synchronization source such as a GPS or network time server.

I do have an RTC with a battery which, as I said, keeps the time while the kids are here. I comment out the line

//RTC.adjust(DateTime(__DATE__, __TIME__));

after setting up the clock and upload the sketch again. Then the clock works a treat until I dismantle it. This is something a built for the five year old over two years ago and it has worked without fail all that time. The only issue I had was the time difference when using the Web IDE

Thank you for your valuable input regarding my OP about the time difference between the IDE and Web IDE.