how the miner start to count the timestamp to insert in the block
The timestamp is set by the miner and is part of the data hashed for the Proof of Work. So it is set at the time the miner begins hashing a particular header and searching for a nonce for it.