<pre><code>&gt;&gt;&gt; import time
&gt;&gt;&gt; time.strptime("01-31-2009", "%m-%d-%Y")
(2009, 1, 31, 0, 0, 0, 5, 31, -1)
&gt;&gt;&gt; time.mktime((2009, 1, 31, 0, 0, 0, 5, 31, -1))
1233378000.0
&gt;&gt;&gt; 60*60*24 # seconds in a day
86400
&gt;&gt;&gt; 1233378000.0 / 86400
14275.208333333334
</code></pre>

<p><code>time.mktime</code> should return the number of seconds since the epoch. Since I'm giving it a time at midnight and the epoch is at midnight, shouldn't the result be evenly divisible by the number of seconds in a day?</p>

[{'answer_id': 21973, 'author': 'Anders Eurenius', 'author_id': 1421, 'author_profile': 'https://Stackoverflow.com/users/1421', 'pm_score': 2, 'selected': False, 'text': '<pre><code>mktime(...)\n    mktime(tuple) -&gt; floating point number\n\n    Convert a time tuple in local time to seconds since the Epoch.\n</code></pre>\n\n<p>local time... fancy that.</p>\n\n<p>The time tuple:</p>\n\n<pre><code>The other representation is a tuple of 9 integers giving local time.\nThe tuple items are:\n  year (four digits, e.g. 1998)\n  month (1-12)\n  day (1-31)\n  hours (0-23)\n  minutes (0-59)\n  seconds (0-59)\n  weekday (0-6, Monday is 0)\n  Julian day (day in the year, 1-366)\n  DST (Daylight Savings Time) flag (-1, 0 or 1)\nIf the DST flag is 0, the time is given in the regular time zone;\nif it is 1, the time is given in the DST time zone;\nif it is -1, mktime() should guess based on the date and time.\n</code></pre>\n\n<p>Incidentally, we seem to be 6 hours apart:</p>\n\n<pre><code>&gt;&gt;&gt; time.mktime((2009, 1, 31, 0, 0, 0, 5, 31, -1))\n1233356400.0\n&gt;&gt;&gt; (1233378000.0 - 1233356400)/(60*60)\n6.0\n</code></pre>\n'}, {'answer_id': 21974, 'author': 'Daren Thomas', 'author_id': 2260, 'author_profile': 'https://Stackoverflow.com/users/2260', 'pm_score': 0, 'selected': False, 'text': "<p>Interesting. I don't know, but I did try this:</p>\n\n<pre><code>&gt;&gt;&gt; now = time.mktime((2008, 8, 22, 11 ,17, -1, -1, -1, -1))\n&gt;&gt;&gt; tomorrow = time.mktime((2008, 8, 23, 11 ,17, -1, -1, -1, -1))\n&gt;&gt;&gt; tomorrow - now\n86400.0\n</code></pre>\n\n<p>which is what you expected. My guess? Maybe some time correction was done since the epoch. This could be only a few seconds, something like a leap year. I think I heard something like this before, but can't remember exactly how and when it is done...</p>\n"}, {'answer_id': 21975, 'author': 'Philip Reynolds', 'author_id': 1087, 'author_profile': 'https://Stackoverflow.com/users/1087', 'pm_score': 3, 'selected': False, 'text': '<p>Short answer: Because of timezones.</p>\n\n<p>The Epoch is in UTC.</p>\n\n<p>For example, I\'m on IST (Irish Standard Time) or UTC+1. <a href="https://docs.python.org/3/library/time.html#time.gmtime" rel="nofollow noreferrer"><code>time.mktime()</code></a> is relative to my timezone, so on my system this refers to</p>\n\n<pre><code>&gt;&gt;&gt; time.mktime((2009, 1, 31, 0, 0, 0, 5, 31, -1))\n1233360000.0\n</code></pre>\n\n<p>Because you got the result 1233378000, that would suggest that you\'re 5 hours behind me</p>\n\n<pre><code>&gt;&gt;&gt; (1233378000 - 1233360000) / (60*60)    \n5\n</code></pre>\n\n<p>Have a look at the <a href="https://docs.python.org/3/library/time.html#time.gmtime" rel="nofollow noreferrer"><code>time.gmtime()</code></a> function which works off UTC.</p>\n'}, {'answer_id': 22021, 'author': 'Daniel Benamy', 'author_id': 2427, 'author_profile': 'https://Stackoverflow.com/users/2427', 'pm_score': 2, 'selected': False, 'text': "<p>Phil's answer really solved it, but I'll elaborate a little more. Since the epoch is in UTC, if I want to compare other times to the epoch, I need to interpret them as UTC as well.</p>\n\n<pre><code>&gt;&gt;&gt; calendar.timegm((2009, 1, 31, 0, 0, 0, 5, 31, -1))\n1233360000\n&gt;&gt;&gt; 1233360000 / (60*60*24)\n14275\n</code></pre>\n\n<p>By converting the time tuple to a timestamp treating is as UTC time, I get a number which <em>is</em> evenly divisible by the number of seconds in a day.</p>\n\n<p>I can use this to convert a date to a days-from-the-epoch representation which is what I'm ultimately after.</p>\n"}]
['https://Stackoverflow.com/questions/21961', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2427/']