use localtime_r() instead of localtime()