1. If the song ends on a D, it is usually in D. But not always.
2. If I song starts on a D, it is usually in D. This rule is broken much more often I find.
3. If the song starts and ends on a D, there is a good chance it is in D.
Notice I say ends first. This is because in western culture we like to have happy endings. This includes music.
Be very careful of rule 2. At jams people usually look at the first chord and say "This one is in D". Sometimes it isn't
But really, analyzing the chords is a much better solution. Song writers sometimes like to start on a different chord from the root just for the effect. Or end on a different chord to "leave you hanging".