A compact two-dimensional (2-D) finite-difference time-domain (FDTD) method is proposed to calculate the resonant frequencies and quality factors of a partially loaded cavity that is uniform in the 𝑧-direction and has an arbitrary cross section in the 𝑥-𝑦 plane. With the description of 𝑧 dependence by 𝑘𝑧, the three-dimensional (3-D) problem can be transformed into a 2-D problem. Therefore, less memory and CPU time are required as compared to the conventional 3-D FDTD method. Three representative examples, a half-loaded rectangular cavity, an inhomogeneous cylindrical cavity and a cubic cavity loaded with dielectric post, are presented to validate the utility and efficiency of the proposed method.