1. When Monkey was Released
Readers would be aware that the Monkey King was eventually freed from his long detention by the Tang Monk on his journey for the Western sutras. The novel states that Tripitaka left the Tang capital during the ninth month of the thirteenth year of Zhenguan (贞观) , which corresponds to the year 639 AD [src. 2].
We shall now tell you about Tripitaka, who, on the third day before the fifteenth of the ninth month in the thirteenth year of the period Zhenguan, was sent off by the Tang emperor and many officials from outside the gate of Chang’an.
The historical Xuanzang embarked his journey in 627 AD, the first year of the Zhenguan period.
Later in the novel, Tripitaka himself mentions that it took him two months to travel a distance of 5000-6000 li , after travelling 5000 li to take in Monkey as a disciple [src. 4].
“Since leaving the outskirts of Chang’an,” said Tripitaka, “I traveled for some five thousand miles before passing the Mountain of Two Frontiers, where I picked up a little disciple. Moving on, we passed through the Hamil Kingdom of the western barbarians, and in two months we had traveled another five or six thousand miles. Only then did we arrive at your noble region.”
Using this statement provided, it is possible to generate a good estimate on the time when Tripitaka freed Monkey from the mountain. The first 5000 li of the journey to Five-Elements Mountain, plus the delay from encountering demons before , would equal to the two months of time it took for him to travel 5000-6000 li. Thus, adding two months to the original ninth month that Tripitaka departed, we can draw up an educated guess that Sun Wukong was released during the eleventh month (i.e. November - December) of the thirteenth year of Zhenguan (i.e. 639 AD).
2. When Monkey was Imprisoned
Just before releasing Monkey from Five-Elements Mountain, Tripitaka was introduced to this particular mountain by a local hunter, Liu Boqin (刘伯钦), who had saved him from several beasts and escorted him here. Liu introduces the mountain as Two-Frontiers Mountain (liangjie shan, 两界山), which was the more recent name of the previously known Five-Elements Mountain. Liu also mentions that the mountain descended from the Heavens at the time when Wang Mang (45 BC-23 AD, 王莽)  usurped the Han (202 BC-220 AD, 汉朝) throne [src. 7-9].
“The ancient name of this mountain,” said the Guardian [Liu Boqin], “was the Mountain of Five Phases [Five Elements]. It was changed to the Mountain of the Two Frontiers as a result of our Great Tang ruler’s western campaigns to secure his empire. A few years ago, I heard from my elders that during the time when Wang Mang usurped the throne of the Han emperor, this mountain fell from Heaven with a divine monkey clamped beneath it.”
Wang Mang’s reigning period lasted from 9-23 AD, but that was after he had overthrown the Han court and seized the throne, and thus cannot be counted as the time he usurped it. According to Theobald (2011), the time Wang officially began usurping the Han dynasty and founded his own Xin dynasty (8-23 AD) was in the winter (i.e. November 8 - December 31) of 8 AD.
From my two analysed points in para. 1-2 above, it makes it possible for us to infer the exact number of years that Sun Wukong was crushed under Five-Elements Mountain for. Taking his jailed 8 AD from his imprisoned 639 AD, that leaves a difference of 631 years, providing us that number as the true amount of years that Monkey was imprisoned for, and although the commonly believed 500 years is not flawlessly accurate, it still remains the popular expression of Sun Wukong’s imprisonment time length.
 Zhenguan (贞观)
Zhenguan is the name of the reigning period of Emperor Li Shimin (李世民), better known as Taizong of Tang (唐太宗). This period lasted historically from 627-649 AD.
 5000 li
A li is a unit of measurement for great distances in traditional China. One li from the Ming dynasty, when Journey to the West was written, is equivalent to 576 metres (630 yards) in modern day. Therefore, 5000 li would equal to 28,800 km or 17,895.5 miles.
 encountering demons before
This is referring to the demons of Double-Fork Ridge (shuangcha ling, 双叉岭) in ch. 13. The three demon kings there are General Yin (yin jiangjun, 寅将军), the Bear Mountain Lord (xiong shanjun, 熊山君) and the Ox Hermit (te chushi, 特处士).
 Wang Mang (王莽)
Wang Mang (45 BC-23 AD) was originally a minister of the Western Han (202 BC-9 AD, 西汉) who usurped the throne and established his own Xin dynasty (8-23 AD, 新朝, lit: the new dynasty). However, he was considered as a reformer by many historians, while others deem him simply as a villain.
"What do you mean by Wukong not being imprisoned for 500 years? So how long was he really imprisoned for?"