[Tutor] Program to report if file was modified today

Kent Johnson kent37 at tds.net
Thu Feb 12 15:19:06 CET 2009


On Wed, Feb 11, 2009 at 11:21 PM, bob gailer <bgailer at gmail.com> wrote:
> David wrote:
>>
>> I get this error with the int(time.localtime())
>>  start_of_today = int(time.localtime())
>> TypeError: int() argument must be a string or a number, not
>> 'time.struct_time'
>
> Should have been start_of_today = int(time.time())

No, that rounds to the current second, not the current day:
In [5]: int(time.time())
Out[5]: 1234438429

In [6]: int(time.time())
Out[6]: 1234438432

In [7]: int(time.time())
Out[7]: 1234438433

Here are two ways to get the time at midnight in seconds since the
epoch. The first one gives local midnight, the second one is UTC:
import time
from datetime import date

Convert datetime.date.today() to seconds:
In [21]: time.mktime(date.today().timetuple())
Out[21]: 1234414800.0

Round down to the nearest whole day:
In [24]: now = int(time.time())

In [27]: now - (now % (60*60*24))
Out[27]: 1234396800

Kent


More information about the Tutor mailing list