Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
298 Vizualizări

Hi guys!!!

Please i want to convert datetime to timestamp but i got this error:


date = 2012-10-29 11:38:22

^

SyntaxError: invalid syntax


Here is the code, please help

from datetime import datetime

import calendar

date = 2012-10-29 11:38:22

print(date)

print(calendar.timegm(date.utctimetuple()))

Imagine profil
Abandonează
Cel mai bun răspuns

1351517902.0! :P

Try with:

from datetime import datetime
import time
# just to be sure about the format: 
fmt = '%Y-%m-%d %H:%M:%S'
source_date = '2012-10-29 11:38:22' 
correct_the_format = datetime.strptime(source_date, fmt) 
# convert to unix timestamp
data_ts = time.mktime(correct_the_format.utctimetuple())
print data_ts

Should work. Let me know.

 



Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
mar. 25
1386
4
apr. 24
174301
0
dec. 23
2188
5
iul. 25
228132
1
dec. 22
3312