[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua how to get current and previous day
- From: Natanael Copa <natanael.copa@...>
- Date: Tue, 14 Sep 2010 16:02:02 +0200
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