X-ray free-electron lasers, with pulse durations ranging from a few to several hundred femtoseconds, are uniquely suited for studying atomic, molecular, chemical and biological systems. Characterizing the temporal profiles of these femtosecond X-ray pulses that vary from shot to shot is not only challenging but also important for data interpretation. Here we report the time-resolved measurements of X-ray free-electron lasers by using an X-band radiofrequency transverse deflector at the Linac Coherent Light Source. We demonstrate this method to be a simple, non-invasive technique with a large dynamic range for single-shot electron and X-ray temporal characterization. A resolution of less than 1 fs root mean square has been achieved for soft X-ray pulses. The lasing evolution along the undulator has been studied with the electron trapping being observed as the X-ray peak power approaches 100 GW.