os.date formatting
Brought to you by:
ian_farmer,
jim_roseborough
Hi,
I am using this code in my lua file:
os.date('STARTED %Y-%m-%d %H:%M', os.time())
First parameter (format) is not taken into account at all I always get the same formatting i.e. Sun Apr 03 21:27:42 CEST 44738
When I run script in standalone lua it works perfectly
Best Regards
I workaround the lack of implementation of the:
by providing the own implementation of the functionality described above.
I used the utility class from Apache Tomcat project to be able to parse the strftime formatting options. Read the limitation of the Apache Strftime class.
I plan to translate the same business logic into the pure Java implementation later. You can run this script from LuaJ environment (tested with 2.0.3 version).
Here is the patch:
~~~~~~~~~~~~~
:::lua
local calendar_class = luajava.bindClass("java.util.Calendar")
local tz_class = luajava.bindClass("java.util.TimeZone")
local java_system = luajava.bindClass("java.lang.System")
os.time = function (t)
if not t then
return java_system:currentTimeMillis() / 1000
end
end
os.date=function(f,t)
if not t then
t = os.time()
end
end
~~~~~~