It seems to me that you could put any time you want in the timestamp.
No, there are specific rules:
A timestamp is accepted as valid if it is greater than the median timestamp of previous 11 blocks, and less than the network-adjusted time + 2 hours. "Network-adjusted time" is the median of the timestamps returned by all nodes connected to you. As a result, block timestamps are not exactly accurate, and they do not even need to be in order. Block times are accurate only to within an hour or two.
Example:
It's December 29th, 2017 at 11:00:00. The median for the previous 11 blocks is the current time - ~1 hour in average. Let's assume that it's exactly 1 hour in this case.
- December 29th, 2017 at 13:00:00 is not accepted
- December 29th, 2017 at 12:59:59 is accepted
- December 29th, 2017 at 9:59:59 is not accepted
- December 29th, 2017 at 10:00:01 is accepted