Figure Analysis
Along with Josiah, Hezekiah is the most righteous king out of all the kings in 2 Kings. (Hezekiah's name means "Strengthened by the Lord.") Apparently he and Josiah are really about as righteous as King David was, though the narrator doesn't say if they have the uniquely beloved status David had in God's eyes. At any rate, that's pretty righteous. The narrator says both of Hezekiah and Josiah that there was no king like them "before or after."
Hezekiah's moment of righteousness and truth comes when he needs to remain faithful to God's commands, when the Assyrians seem sure to besiege and then annihilate Jerusalem. His piety is best exemplified by the prayer he offers up to God, asking him to save them from the Assyrians (which he does):
Incline your ear, O Lord, and hear; open your eyes, O Lord, and see; hear the words of Sennacherib, which he has sent to mock the living God. Truly, O Lord, the kings of Assyria have laid waste the nations and their lands, and have hurled their gods into the fire, though they were no gods but the work of human hands—wood and stone—and so they were destroyed. (2 Kings 19:16-18)
God reciprocates by annihilating the Assyrian army.
But Hezekiah isn't just a devoted man—he'll beg for his life when he needs to. When he seems to be dying, he asks God to save him. God happens to be pretty favorably disposed towards Hezekiah, so he grants him another fifteen years of life, moving back the shadow on a sundial as a symbol of the lost time he's restoring to him. God demonstrates the same point he made by annihilating the Assyrians: he's not just an actor in history, but the ruler of history and of time itself.