In this paper a distributed algorithm for clock synchronization is proposed. This algorithm is based on an extension of the consensus algorithm able to synchronize a family of double integrators. Since the various clocks may have different drifts, the algorithm needs to be designed so that it can work also in case of heterogeneous double integrators. Through a robust control analysis it is possible to determine the maximum admissible level of heterogeneity yielding synchronization. The first part of the paper is devoted to the analysis of an unrealistic synchronous implementation of the algorithm. However, in the last part of the paper we propose a realistic pseudo-synchronous implementation which is proved to be a perturbation of the synchronous one. From arguments related the center manifold theorem, the stability of the pseudo-synchronous is finally proved.