Use reentrant version of ctime() and localtime()

Replace a while loop with strstr() with a single strrchr() call.