Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'datetime.time' has no 'mktime'

I'm trying to convert a datetime object to a UNIX timestamp (preferably in milliseconds, though I wouldn't mind with and without).

Mktime seems to be the method that usually gets it, however I keep getting the error:

AttributeError: type object 'datetime.time' has no attribute 'mktime'.

Can anyone tell me what I'm doing wrong? I keep going round in circles!

like image 928
Federer Avatar asked Aug 17 '09 12:08

Federer


2 Answers

I think you have done

from datetime import datetime, time

instead of

import time
from datetime import datetime

so that the object called time is actually coming from the datetime module, not the time module.

like image 94
Daniel Roseman Avatar answered Sep 19 '22 15:09

Daniel Roseman


Actually, even using the above answer, I still got the same error message.

I´ve solved my problem using

>>>>from time import mktime as mktime
>>>>today = mktime(2012, 12, 21, 0, 0, 0, 0, 0, 0)

I don't know the why, but, it only worked using the alias (as mktime)... can somebody tell me the reason ...

like image 24
Diego Favero Avatar answered Sep 17 '22 15:09

Diego Favero