Mercurial Hosting > luan
view core/src/luan/modules/Time.luan @ 254:e0fb8a49e031
add Time.luan
git-svn-id: https://luan-java.googlecode.com/svn/trunk@255 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Mon, 27 Oct 2014 20:45:05 +0000 |
parents | |
children | 15122d724ce4 |
line wrap: on
line source
-- incomplete, will add as needed import "String" import "Table" import "Java" import "java.lang.System" import "java.util.Calendar" import "java.util.Date" import "java.text.SimpleDateFormat" function now() return System.currentTimeMillis() end -- add more as needed local fields = { year = Calendar.YEAR; month = Calendar.MONTH; day_of_month = Calendar.DAY_OF_MONTH; } function get( time, ... ) local cal = Calendar.getInstance() cal.setTimeInMillis(time) local rtn = {} for i, v in ipairs{...} do local fld = fields[v.lower()] fld or error("invalid field: "+v) local n = cal.get(fld) if fld == "month" then n = n + 1 end rtn[i] = n end return Table.unpack(rtn) end function format(time,pattern) return SimpleDateFormat.new(pattern).format(Date.new(time)) end