Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
284 Переглядів

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()))

Аватар
Відмінити
Найкраща відповідь

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.

 



Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
0
бер. 25
1381
4
квіт. 24
174296
0
груд. 23
2183
5
лип. 25
228105
1
груд. 22
3298