The problem when you use mktime is that it converts your python datetime (with/without dst) to your localtime. But if you want to convert it only to a normal unixdatetime without tz you need to create an own function. Here is an example that Ive used for a project:

def dt2ut(date):
    total = ((date.year-1970)*365) + int(float((date.year-1970))/4.0)
    monthdays=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    for i in range(1,date.month):
        total = total + monthdays[i-1]
    total = total + date.day
    total = total*86400 + 3600*date.hour + 60*date.minute + date.second + 1e-6*date.microsecond
    return int(total*100)*10

  • Share/Bookmark