As an important part of new generation of information technology, Internet of Things (IoT), which is developing rapidly, requires high time accuracy. However, malicious nodes located in an IoT network can influence clock synchronization. The security issues of time transfer and consistency are critical and challenging. In this paper, we propose a secure scheme based on blockchain to solve the problem of time synchronization in IoT. In the distributed network of IoT, a blockchain is utilized to record and broadcast time in order to reduce attacks from external environments with the property of passing trust. Moreover, this scheme has the advantage of low-latency by employing a consensus mechanism based on Proof of Stability. Serious analysis and simulation show that the scheme can effectively resist malicious attacks and reduce the latency of consensus process by comparing with traditional methods.