tamus
tamus

Reputation: 53

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

I'm getting this attribute error either because I'm importing the modules or else referencing them incorrectly.

from datetime import date, timedelta, datetime, time, tzinfo

with

def utc2local (utc):
    epoch = time.mktime(utc.timetuple())
    offset = datetime.fromtimestamp (epoch) - datetime.utcfromtimestamp (epoch)
    return utc + offset

called by

(utc2local(rise), utc2local(set))

which gives me - AttributeError: type object 'datetime.time' has no attribute 'mktime'

I have changed my imports to

import time
from datetime import date, timedelta, datetime, tzinfo

but I get - TypeError: 'module' object is not callable

How should I be calling the modules or what should I be using to reference them, thanks

Upvotes: 3

Views: 15778

Answers (1)

Dwi Sulfahnur
Dwi Sulfahnur

Reputation: 46

you don't need to import datetime Just do it:

import time
time.mktime(your_time)

or

from time import mktime
mktime(t)

source: https://www.tutorialspoint.com/python/time_mktime.htm

Upvotes: 1

Related Questions