Determine the center of the dihedral group of order 12

Determine the center of the dihedral group of order 12.

This was asked in an exam so I presume there must be a more efficient way of doing it than actually going through all the elements of a group G and checking that they commute with every other element.

When searching for an answer online I also came across this question - "The centre of a group $G$ consists of all elements $z$ such that $zg = gz$ for all $g \in G$. For each $n$, ﬁnd the centre of the dihedral group $D_n$".

Which leads me to believe there must be some formula for determining the centre of a dihedral group of any order.

It is the half-twist. If you have an $2n$-gon, then rotate it by $n$. This is your centre (along with the trivial element).
Note that for $G=\langle a, b, \ldots, c\rangle$ we have that $g\in Z(G)\Leftrightarrow ga=ag, gb=bg, \ldots, gc=cg$. That is, $g$ is in the centre if and only if it commutes with all the generators.
You can prove that the half-twist is central by rotating the $2n$-gon in your head: Clearly the rotating generator $\alpha$ commutes with the half-twist (for the half-twist is $\alpha^n$), while the flip generator $\beta$ commutes with it too as $\alpha^n$ fixes the two vertices on the line of symmetry through the "initial" vertex.
You can show $\alpha^n$ is the only non-trivial element of the centre by realising that every element has the form $\alpha^i$ or $\alpha^i\beta$ or $\beta$. Then, think about what these elements do to $\alpha$ and to $\beta$. The way I would do this is by using the fact that $ab=ba\Leftrightarrow aba^{-1}=b$, so you have to verify that $\alpha^i\beta\alpha^{-i}\neq \beta$ (unless $i=n$) and $\beta^{-1}\alpha^{-i}\alpha\alpha^i\beta=\beta\alpha\beta\neq\alpha$ (this last bit covers the last two cases - that $\alpha^i\beta$ and $\beta$ are not central). Do the flipping in your head - it is good practice!