Abstract--Time synchronization and localization are two important issues in wireless sensor networks. Although these two problems share many aspects in common, they are traditionally treated separately. In this paper, we present a unified framework to jointly solve time synchronization and localization problems at the same time. Furthermore, since the accuracy of synchronization and localization is very sensitive to the accuracy of anchor timings and locations, the joint time synchronization and localization problem with inaccurate anchors is also considered in this paper. For the case with accurate anchors, the joint maximum likelihood estimator and a more computationally efficient least squares (LS) estimator are proposed. When the anchor timings and locations are inaccurate, a generalized total least squares (GTLS) scheme is proposed. Cram