Python : convertir une heure sous forme de chaîne en horodatage

Document 对象参考手册Exemples Python3

Étant donné une chaîne de temps, la convertir en horodatage.

Exemple

import time a1 = "2019-5-10 23:40:00" # D'abord convertir en tableau de temps timeArray = time.strptime(a1, "%Y-%m-%d %H:%M:%S") # Convertir en horodatage timeStamp = int(time.mktime(timeArray)) print(timeStamp) # Conversion de format - convertir en / a2 = "2019/5/10 23:40:00" # D'abord convertir en tableau de temps, puis convertir vers d'autres formats timeArray = time.strptime(a2, "%Y/%m/%d %H:%M:%S") otherStyleTime = time.strftime("%Y/%m/%d %H:%M:%S", timeArray) print(otherStyleTime)

L'exécution du code ci-dessus produit la sortie :

1557502800
2019/05/10 23:40:00

Document 对象参考手册Exemples Python3

Autres extensions