Skip to main content
Associate
May 27, 2024
Solved

RTC to Coordinated Universal Time (UTC)

Hello everyone, I am using an STM32U575RG, and I would like to know if anyone can help me understand or show me how to use the RTC and convert it to Coordinated Universal Time (UTC).

This topic has been closed for replies.
Imen.DBest answer
ST Technical Moderator
May 28, 2024

Hello @inouee, 

Make sure to enable the RTC Clock, initialize the RTC with the current time and date, configure correctly (LSE, LSI, or HSE) and configure the prescaler to obtain the RTC clock. 

To convert to Coordinated Universal Time (UTC), you need to use the standard C-library functions in <time. h> to convert the time and date. Then, adjust the local time to get the UTC time. (Add or subtract X hours from the time to convert.). For example, if your local time zone is UTC+2 hours, subtract 2 hours from the RTC time to convert it to UTC. If daylight saving time applies, adjust accordingly.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks

1 reply

Imen.DBest answer
ST Technical Moderator
May 28, 2024

Hello @inouee, 

Make sure to enable the RTC Clock, initialize the RTC with the current time and date, configure correctly (LSE, LSI, or HSE) and configure the prescaler to obtain the RTC clock. 

To convert to Coordinated Universal Time (UTC), you need to use the standard C-library functions in <time. h> to convert the time and date. Then, adjust the local time to get the UTC time. (Add or subtract X hours from the time to convert.). For example, if your local time zone is UTC+2 hours, subtract 2 hours from the RTC time to convert it to UTC. If daylight saving time applies, adjust accordingly.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks