If you insist on knowing the grammar, here are a few fun facts:
1. Prepositions of time are used to answer the questions "when" or "for how long".
2. Unlike prepositions of place, they don't change the case. Each preposition of time is followed by one case only.
For example, an and in (time) are always followed by the dative.
an + dem = am
in + dem = im