Write timestamp directly to output stream

This uses put_time (if supported) to avoid having to first write the timestamp to a temporary buffer and then copy it to the stream.