File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1+ require " timespan"
12print (" =================os.time test===============" )
23print (os.time ())
34print (os.time ({day = 26 ,month = 4 ,year = 2018 }))
@@ -16,4 +17,6 @@ print(os.date("%Y"))
1617-- 显示当前是一年中的第几周
1718print (os.date (" %U" ))
1819-- 组合格式化时间
19- print (os.date (" %Y-%m-%d, %H:%M:%S" ,os.time ()))
20+ print (os.date (" %Y-%m-%d, %H:%M:%S" ,os.time ()))
21+
22+ print (getRemainTime (" 24:00:00" ))
Original file line number Diff line number Diff line change 1+ Split = function (szFullString ,szSeprator )
2+ local nFindStartIndex = 1
3+ local nSplitIndex = 1
4+ local nSplitArray = {}
5+ while true do
6+ local nFindLastIndex = string.find (szFullString ,szSeprator ,nFindStartIndex )
7+ if not nFindLastIndex then
8+ nSplitArray [nSplitIndex ] = string.sub (szFullString ,nFindStartIndex ,string.len (szFullString ))
9+ break
10+ end
11+ nSplitArray [nSplitIndex ] = string.sub (szFullString ,nFindStartIndex ,nFindLastIndex - 1 )
12+ nFindStartIndex = nFindLastIndex + string.len (szSeprator )
13+ nSplitIndex = nSplitIndex + 1
14+ end
15+ return nSplitArray
16+ end
17+
18+ formatTime = function ( timeStr )
19+ local splited = Split (timeStr , " :" )
20+ local h = splited [1 ]
21+ local m = splited [2 ]
22+ return tonumber (h ), tonumber (m )
23+ end
24+
25+ getRemainTime = function (timeStr )
26+ local h1 , m1 = formatTime (timeStr )
27+ local curTime = os.date (" *t" , os.time ())
28+ local curH = curTime .hour
29+ local curM = curTime .min
30+
31+ local remainH = h1 - curH
32+ local remainM = m1 - curM
33+ local totalRemainSeCond = remainH * 3600 + remainM * 60
34+ return totalRemainSeCond
35+ end
You can’t perform that action at this time.
0 commit comments