Einstein’s general theory of relativity predicts that time passes slower near a large mass due to the effect of gravity. That is to say that a large mass (eg a planet) warps the fabric of four-dimensional spacetime. This is the first part of J. A. Wheeler’s pithy statement that "Matter tells spacetime how to curve. Spacetime tells matter how to move." The fact that space and time are fundamentally inseparable means that we can’t take time out of the dimension of space in which it applies. Contrary to our natural intuition, at a fundamental level there is no such thing as observer-independent time (ie no such thing as absolute time).
Let’s try to understand this better.
First, Special Relativity. This is a theory based on two postulates: that the speed of light is a universal constant for all observers, and that the laws of physics are the same in all inertial (non-accelerating) frames of reference. The consequence of accepting the first postulate in the setting of the second is what make the Special theory of Relativity so nonintuitive. If you take a photon in a vacuum and observe how fast it travels within the confines of three dimensional space then it goes at a universally agreed speed - ie the speed of light (299 792 458 m/s) - irrespective of the relative velocity of any observer within that space. Quite simply: if the speed of a photon is a universally agreed constant then space (ie distance) and time cannot be universally agreed constants. Thankfully the speed of light is enormous and the effect on space and time isn’t “otherworldly” in real world situations. But it matters - not necessarily quantitatively, rather as a concept that glimpses into the fundamental nature of the universe.
So we move to our first thought experiment. Take two observers and give them each an identical photon clock that ticks a single photon between two parallel mirrors. The photon bouncing between the two mirrors can be taken as a measure of time. Put one observer and his photon clock into a rocket ship and leave the other with his photon clock static within space. Stand beside the static observer and observe his clock with the photon ticking between the two mirrors. Now look at the observer in the rocket ship travelling at a certain velocity. Say that he has orientated the two mirrors parallel to his direction of travel so you see the photon moving in an oblique line as it bounces between the two mirrors (taking into account both the travel of the photon between the two mirrors and the travel of the rocket ship). As the speed of the photon is a universal constant then - from your point of view standing beside the static observer - it takes longer for one tick of the photon clock to pass in the rocket ship (because the photon takes an oblique path and time=distance/speed) than it takes for one tick to pass in the photon clock beside you (where the photon simply passes up and down). That is to say that time is passing slower in the rocket ship than it is in static space.
Each observer, whether they be in the rocket ship or static in space, will notice time passing exactly the same as it always has. This happens whether time is measured with a photon clock or a biologic clock. It is only when the observer in the rocket ship decides to return to the observer in static space that the difference in time is comparative (the observer in the rocket ship will be younger).
This is time dilation in the Special theory of Relativity.
Now we can move on to Einstein’s equivalence principle. In simple terms, this is the equivalence of gravitational mass to inertial mass. That is to say that a man standing in a rocket ship that is constantly accelerating in space at 1g (9.8 m/s2) is in the equivalent environment as a man standing on Earth in the presence of gravity. If the man stands on a weighing machine in either situation he would see the same reading. If he performs an experiment within either situation the outcome would also be the same (so long as the measuring devices are within that same environment). In other words, there is no way to tell the difference between these two environments without the ability to look outside. Einstein tells us that gravitational force is equivalent to the pseudo-force seen in a constantly accelerating frame of reference*.
Now imagine the man within the rocket that is now floating freely in space. The man also floats freely in the space within that rocket. Now take the rocket and let it free fall to earth at 9.8 m/s2. The man within the rocket also free falls at the same acceleration and is again unable to tell the difference between the two environments. Unless he looks outside he is unable to tell whether he is floating out in space or crashing to his doom within a gravitational field. Indeed, the two environments remain equivalent.
This was Einstein’s breakthrough idea that evolved the Special theory of Relativity into the General theory of Relativity.
Just as the acceptance of the speed of light as a universal constant allows us to understand how time passes more slowly the faster an object travels, the equivalence principle allows us to understand how time dilation occurs in the presence of a gravitational field.
This leads us to our second thought experiment. Imagine two observers in a rocket ship that is constantly accelerating in space at 1g (9.8 m/s2). Each observer has an identical clock and one chooses to sit at the top of the ship and the other at the bottom. The top observer sends down a photon every second to the bottom observer. Because the rocket ship is constantly accelerating then the bottom observer is constantly accelerating towards the photons sent by the top observer. That means that the bottom observer measures the time lapse between the first photon and the second to be less than a second apart, that between the second photon and the third photon less again, and so forth. That is to say that time passes slower for the observer at the bottom of the rocket ship than that for the observer at the top of the rocket ship (ie 100 photons representing 99 seconds of elapsed time at the top is measured in less than 99 seconds of elapsed time by the observer at the bottom). If a uniform gravitational field is equivalent to a rocket ship travelling at a uniform acceleration then time passes slower the closer one is to the centre of the gravitational mass.
Again, each observer, whether they be at the top of a mountain (or at the top of the rocket ship) or at sea level (or at the bottom of the rocket ship), will notice time passing exactly the same as it always has. It is only when they decide to meet that the elapsed time is comparative. In this case the frame of reference from which the observer moves has no consequence on the measure of elapsed time.
This is time dilation in the General theory of Relativity.
* more accurately, gravitational force is equivalent to the pseudo-force seen in a constantly accelerating frame of reference when taken to a scale small enough to exclude the effect of tidal forces