How to identify the influential spreaders in social networks is crucial for accelerating/hindering information diffusion, increasing product exposure, controlling diseases and rumors, and so on. In this paper, by viewing the k-shell value of each node as its mass and the shortest path distance between two nodes as their distance, then inspired by the idea of the gravity formula, we propose a gravity centrality index to identify the influential spreaders in complex networks. The comparison between the gravity centrality index and some well-known centralities, such as degree centrality, betweenness centrality, closeness centrality, and k-shell centrality, and so forth, indicates that our method can effectively identify the influential spreaders in real networks as well as synthetic networks. We also use the classical Susceptible-Infected-Recovered (SIR) epidemic model to verify the good performance of our method.