One of the key challenges in scientific researches based on free-electron lasers (FELs) is the characterization of the coherence time of the ultra-fast hard x-ray pulse, which fundamentally influences the interaction process between x-rays and materials. Conventional optical methods, based on autocorrelation, are very difficult to realize due to the lack of mirrors. Here, we experimentally demonstrate a novel method which yields a coherence time of 174.7 attoseconds for the 6.92 keV FEL pulses at the Linac Coherent Light Source. In our experiment, a phase shifter is adopted to control the cross-correlation between x-ray and microbunched electrons. This approach provides critical diagnostics for the temporal coherence of x-ray FELs and is universal for general machine parameters; applicable for wide range of photon energy, radiation brightness, repetition rate and FEL pulse duration.