Core/Misc: Remove unsafe not thread-safe localtime() calls

Replace not thread-safe localtime() calls with thread-safe localtime_r().

(cherry picked from commit 5b08387792dae0afbf91ab74808dc978bf418bca)