Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
253:dddf4e85bfe4 | 254:e0fb8a49e031 |
---|---|
1 -- incomplete, will add as needed | |
2 | |
3 import "String" | |
4 import "Table" | |
5 import "Java" | |
6 import "java.lang.System" | |
7 import "java.util.Calendar" | |
8 import "java.util.Date" | |
9 import "java.text.SimpleDateFormat" | |
10 | |
11 | |
12 function now() | |
13 return System.currentTimeMillis() | |
14 end | |
15 | |
16 -- add more as needed | |
17 local fields = { | |
18 year = Calendar.YEAR; | |
19 month = Calendar.MONTH; | |
20 day_of_month = Calendar.DAY_OF_MONTH; | |
21 } | |
22 | |
23 function get( time, ... ) | |
24 local cal = Calendar.getInstance() | |
25 cal.setTimeInMillis(time) | |
26 local rtn = {} | |
27 for i, v in ipairs{...} do | |
28 local fld = fields[v.lower()] | |
29 fld or error("invalid field: "+v) | |
30 local n = cal.get(fld) | |
31 if fld == "month" then | |
32 n = n + 1 | |
33 end | |
34 rtn[i] = n | |
35 end | |
36 return Table.unpack(rtn) | |
37 end | |
38 | |
39 function format(time,pattern) | |
40 return SimpleDateFormat.new(pattern).format(Date.new(time)) | |
41 end |