What's an anachronism?

An anachronism occurs when a character is placed in a place or situation that could not be possible during that person's lifetime. For example, if you were to write a story of a person living in the 21st century who meets Shakespeare, the story would be anachronistic.
In his plays, Shakespeare did not spend much time making sure that dates and people in his plays fit where he put them. For example, Hamlet lived in 7th-century Denmark, but Shakespeare has him studying at Wittenberg, a university founded in 1502. This reference helped Shakespeare's audience to identify with the play and its characters. The audience would recognize that Hamlet is a scholar, that he is probably a Protestant, and that he would most likely be a skeptic — not a believer in spirits and ghosts.