It is impossible for the blocks to deviate from the time by more than 2 hours. Nodes will reject any blocks that:
- Have a lower timestamp than the median of the previous 11 blocks
- Deviate from the network adjusted time (Average time given by the nodes connected) by 2 hours.
Okay thanks. But if the network time is the average time of connected nodes, couldn't a miner simply give a wrong time in order to push up the average?
Each node sends the their timestamp at the time of connection and the nodes will store the timestamp. If it sees a block that doesn't fulfill their adjusted time, it is rejected. The miner cannot change the network adjusted time, only the nodes connected to each other can.