If a and B are real symmetric matrices, it is necessary and sufficient that a and B have the same eigenvalues. Why?

If a and B are real symmetric matrices, it is necessary and sufficient that a and B have the same eigenvalues. Why?

It is a theorem that similar matrices have the same eigenvalues
On the contrary, because a and B are real symmetric matrices, a can be diagonalized, that is, a and B are similar to the same diagonal matrix composed of eigenvalues, so a and B are similar