Based on Density Functional Theory (DFT), using first-principles pseudopotential plane wave method, elastic properties and electronic structure of TiB2 and ZrB2 were calculated. The elastic constants of these compounds were calculated by Voigt-Reuss-Hill method. The results show that the elastic modulus of TiB2 and ZrB2 are 594 and 520 GPa, and the shear modulus are 268 and 229 GPa, respectively. Pugh empirical criterion and Poisson's ratio show that the two compounds are very brittle, and the brittleness of TiB2 is higher than ZrB2. Finally, the differences in elastic properties between TiB2 and ZrB2 result form their electronic structures.