We see the beginning of the Death Star's construction at the end of Star Wars Episode III: Revenge of the Sith. As Star Wars Episode IV: A New Hope officially takes place 19 years later, we may wonder why it took the Empire so long to get the thing built. It is especially confusing in the light of Star Wars Episode VI: Return of the Jedi, where a second, fully operational (though incomplete), Death Star was shown, no more than four years having passed since the destruction of the first.
The obvious source for the answer would be creator George Lucas. During the commentary track on the DVD of Attack of the Clones, he shortly addresses the matter, and suggests that the Empire may have had problems with the contractors and construction workers who were hired to build the first Death Star (who were mostly Geonosians, since they designed the station in the first place). It should be noted that he may be referring in a tongue-in-cheek way to the famous dialogue from the movie Clerks, where the characters discussed the issue of contractors and workers being involved in the construction of both Death Stars, and dying in the destructions.
Joke or not, this could of course be a good reason why the construction of the first Death Star had slowed down. Remember that it was still a prototype; perhaps there were problems with the supply of materials, difficulties in implementing the new technology, lack of engineers, inexperience, growing pains in the mechanisms, deliberate sabotage by adversaries, etc.
The video game Star Wars Battlefront II features a story mode that contains a mission of sabotage toward the first Death Star before the events of Episode IV, though this is obviously an after-the-fact rationalization not originally considered when Lucas was writing the story.
This may go some way towards explaining why the second Death Star was constructed so much faster: it was no longer a prototype, and although production of a Death Star does not seem exactly like assembly work, previous experience may have significantly sped up construction. And although operational, it was still far from completed.
Another consideration is that it is not literally stated that the construction of Death Star 2 was started after the destruction of the first; perhaps they had already started building a second one while the first one was being finished. They must have considerably reworked the original plans, because the design flaw in the first Death Star (that it can be destroyed by firing a simple torpedo in the exhaust port) was eliminated in the second one.
It is possible that the end of Episode III, where Vader and the Emperor are looking on the construction of the Death Star, took place some time after the other events shown in the ending montage. There is, however, nothing in the scene to suggest this, nor any precedent for scenes in a Star Wars film being presented as flash-forwards or flashbacks.
A more factual line of logic would be that it should be no surprise that when it takes years to build an aircraft carrier, it should take a little longer to build something the size of a moon, especially since it was supposed to be a secret construction project (hard to hide a new moon, or the sudden disappearance of a million zero-g construction workers). As for why the second was built so much faster, just like in the movie Contact, why build just one when you can build two almost as easily? The hard parts were fabrication of new dies and tech. Once you can make it once, you just have to put a nominal cost into making a duplicate of all the new parts.