lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Sep 14, 2010 at 3:10 PM, Ted Unangst <ted.unangst@gmail.com> wrote:
> On Tue, Sep 14, 2010 at 5:30 AM, soly man <luascript2010@gmail.com> wrote:
>> Dear friends
>>
>> I have  the following lua code and i want to get the current day and
>> the previous day
>
> Option 1:
> now = os.time()
> yesterday = now - 3600*24
> print(os.date("...", yesterday))

This might give you weird bugs once in a while as it wrongly assumes
that a day is always 3600 * 24 hours. You need take leap years and
leap seconds in consideration.

>
> Option 2:
> t = os.date("*t")
> t.day = t.day - 1
> yesterday = os.time(t)

I think this should work.

-- 
Natanael Copa