Replace localtime() with thread safe localtime_r()