cancel
Showing results for 
Search instead for 
Did you mean: 

Function/Library to convert between UTC time and Local Time

YSN
Senior

Is there any function or library associated with STM32 Device to convert the UTC time to Local Time and Vice versa ?

1 ACCEPTED SOLUTION

Accepted Solutions

Use the standard C-library functions prototyped in <time. h> to convert the date/time to UNIX epoch-based time, add or subtract the timezone-specific amount, then convert back.

You'll still have to supply the rules,it is application-specific how rigorously have they (mainly DST) be observed (e.g. if historical data have to be included, minor/exotic geographical exceptions, etc.)

JW

View solution in original post

3 REPLIES 3
TDK
Guru

The STM32 has no way of knowing what timezone it's in unless you provide that information. You add or subtract X hours from the time to convert.

As timezones are complex, arbitrary, and subject to change, this complexity is typically left out of the embedded system.

If you feel a post has answered your question, please click "Accept as Solution".

You are right, I was too expecting embedded C function / library to make conversions !

I understand that this is out of context for MCU, but was mentioning to get some examples if it is already done by somebody else.

Use the standard C-library functions prototyped in <time. h> to convert the date/time to UNIX epoch-based time, add or subtract the timezone-specific amount, then convert back.

You'll still have to supply the rules,it is application-specific how rigorously have they (mainly DST) be observed (e.g. if historical data have to be included, minor/exotic geographical exceptions, etc.)

JW