lua-users home
lua-l archive

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


On 28 July 2016 at 22:08, Marc Balmer <marc@msys.ch> wrote:
> On OS X, strftime supports the %s format, resulting in the number of seconds
> since the epoch.
>
> The attached small diff makes this usable on OS X using os.date('%s')
>
> Before:
>
> Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio
>> print(os.date("%s:%M:%H %d/%m/%Y"))
> stdin:1: bad argument #1 to 'date' (invalid conversion specifier '%s:%M:%H %d/%m/%Y')
>
> With the patch applied:
>
> Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio
>> print(os.date("%s:%M:%H %d/%m/%Y"))
> 1469707450:04:14 28/07/2016
>
> I don't know if %s is in ISO C 99 or POSIX, but OS X certainly supports it.

Not only is %s not standardised, it's broken in most libcs I tested
(as I found out a couple of years ago[1][2])

I suggest staying away from it.

 [1] https://sourceware.org/bugzilla/show_bug.cgi?id=17189
 [2] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=192016