我怎样才能得到最后修改的时间戳在Lua中 [英] How can I get last modified timestamp in Lua
本文介绍了我怎样才能得到最后修改的时间戳在Lua中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我可以打开,读取,写入,关闭这些文件。
$ b
本地session_debug = io.open(/ root / session_debug.txt,a)
session_debug:write(Some text \\ \\ n)
session_debug:close()
如何知道上次修改日期这个文件的时间戳。
解决方案
标准Lua没有内置函数。没有第三方库的一种方法是使用 io.popen
。
例如,在Linux上,您可以使用 stat
:
$ p $ local $ c $ local $ f $ :read()
现在 last_modified
是最后修改时间 testfile
的时间戳。在我的系统上,
print(os.date(%c,last_modified))
输出 Sat Mar 22 08:36:50 2014
。
I am trying to work on Lua file handling.
So, I am able to open, read, write, close the files.
local session_debug = io.open("/root/session_debug.txt", "a")
session_debug:write("Some text\n")
session_debug:close()
How can I know the last modified date timestamp of this file.
解决方案
There's no built-in function in standard Lua that does this. One way to get it without third-party libraries is to take use of io.popen
.
For example, on Linux, you could use stat
:
local f = io.popen("stat -c %Y testfile")
local last_modified = f:read()
Now last_modified
is the timestamp of the last modified time of testfile
. On my system,
print(os.date("%c", last_modified))
Outputs Sat Mar 22 08:36:50 2014
.
这篇关于我怎样才能得到最后修改的时间戳在Lua中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文