Use gmtime_r() and localtime_r() instead of non-thread-safe versions.