We offer an innovative optical material parameter extraction algorithm for Terahertz time-domain spectroscopy (THz-TDS). Unlike previously reported extraction algorithms in frequency domain, which have to be compromised between amplitude and phase, or the real part and imaginary part of the transfer function, we calculate material parameters by minimizing the difference between the measured sample waveform and the rebuilt one in time domain. The new method is effectively verified by different samples, and can be used either in transmission mode or in reflection mode for THz-TDS.