Use gmtime_r instead of gmtime and localtime_r instead of localtime