Smart cities are designed to satisfy the needs of residents and improve their quality of life by providing a wide range of smart city services. The key to the efficient operation of smart city services is accurate forecast of the missing QoS (Quality of Service).. At present, many approaches utilize the context information of users and services, such as geographic location and network location, to somewhat increase the prediction accuracy and forecast the missing QoS values.. However, because the network conditions and server status are unpredictable, time is also considered as one of the important factors affecting QoS prediction, which brings more challenges as follows: higher data dimension, more complex data characteristics and higher data sparsity. To overcome these challenges,z we suggest an approach for time-aware Web service QoS prediction based on contrastive learning(named CLpred). CLpred utilizes a sequential data input format for QoS data and models these QoS sequences through Transformer encoder with contrastive learning framework. Therefore, it can downscale QoS data and extract a more efficient representation in complex QoS data. Furthermore, it makes it possible to apply data augmentation methods to address these probelms of data sparsity. In order to prove the superiority of the this approach, particularly inside the presence of extremely high data sparsity, extensive tests are carried out on the well-known service QoS data set WSDREAM.