'datetime.time' doesn't matter 'mktime'

I am trying to convert a datetime object to a UNIX timestamp (preferably in milliseconds, although I would not mind with and without).

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

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

Can someone tell me what I am doing wrong? I continue around!

+6
python datetime
source share
2 answers

I think you did

from datetime import datetime, time 

instead

 import time from datetime import datetime 

so the object named time actually comes from the datetime module, not the time module.

+20
source share

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

I solved the problem using

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

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

+1
source share

All Articles