Date.lua

来自 阿尔派Linux

函数

date_to_seconds

输入
此库函数需要以下输入/参数。

  • 日期表
    • 示例: t = { {year=2000,month=12,day=13}, {year=1987,month=4,day=30,hour=10}, {year=2020,month=1,day=10} }

输出
此库函数提供以下输出/参数。

  • 自 1970 年以来的秒数排序的日期表
    • temp = { 546775200, 976708800, 1578657600 }

编码示例

-- Include/Call for this library
require("date")
temp = date.date_to_seconds(t) --see table t above
for a,b in ipairs(temp) do print(b) end
--546775200 
--976708800
--1578657600

seconds_to_date

输入
此库函数需要以下输入/参数。

  • 自 1970 年以来的秒数表
    • 示例: t = { 546775200, 976708800, 1578657600 }

输出
此库函数提供以下输出/参数。

  • 将给出一个包含格式化字符串的表
    • temp = { {Thu Apr 30 10:00:00 UTC 1987}, {Wed Dec 13 12:00:00 UTC 2000}, {Fri Jan 10 12:00:00 UTC 2020} }

编码示例

-- Include/Call for this library
require("date")
temp = date.seconds_to_date(t) --see t above
-- the formated string is found in the top of date.lua 
-- is format = "%a %b %d %X %Z %Y"

string_to_table

输入
此库函数需要以下输入/参数。

  • 带有日期的格式化字符串 (格式为 os.date("%a %b %d %X %Z %Y"))
    • 示例: str = "Mon Nov 26 19:56:10 UTC 2007"

输出
此库函数提供以下输出/参数。

  • 将给出一个包含 year, month, day, hour, min, sec, isdst 的表

编码示例

-- Include/Call for this library
require("date")
temp = date.string_to_table(os.date(date.format))

date_diff

输入
此库函数需要以下输入/参数。

  • 两个日期(以秒为单位)的差值
    • 示例: (546775200, 976708800)
      • Thu Apr 30 10:00:00 UTC 1987, Wed Dec 13 12:00:00 UTC 2000

输出
此库函数提供以下输出/参数。

  • 一个表
    • temp = { min=0, day=17, month=8,sec=0,hour=2, year=13}

编码示例

-- Include/Call for this library
require("date")
temp = date.date_diff(546775200, 976708800)
--temp will be valued as above. This will not be completely accurate in relation to leap years...

num_month_name

输入
此库函数需要以下输入/参数。

  • 要匹配的月份数字

输出
此库函数提供以下输出/参数。

  • 月份全名的字符串

编码示例

-- Include/Call for this library
require("date")
print(date.num_month_name(7)
--July

num_month_name_abr

输入
此库函数需要以下输入/参数。

  • 数字

输出
此库函数提供以下输出/参数。

  • 3 个字母缩写的字符串

编码示例

-- Include/Call for this library
require("date")
print(date.num_month_name_abr(7)
--Jul

name_month_num

输入
此库函数需要以下输入/参数。

  • 字符串 - 要匹配的月份全名

输出
此库函数提供以下输出/参数。

  • 匹配的月份数字

编码示例

-- Include/Call for this library
require("date")
print(date.name_month_num("July")
--7

abr_month_num

输入
此库函数需要以下输入/参数。

  • 月份名称缩写的字符串

输出
此库函数提供以下输出/参数。

  • 月份数字

编码示例

-- Include/Call for this library
require("date")
print(date.abr_month_num("Jul")
--7

num_dow_name

输入
此库函数需要以下输入/参数。

  • 星期几的数字
    • 从星期日开始 - 星期六

输出
此库函数提供以下输出/参数。

  • 月份全名的字符串

编码示例

-- Include/Call for this library
require("date")
print(date.num_dow_name(6)
--Friday

num_dow_abr

输入
此库函数需要以下输入/参数。

  • 星期几的数字
    • 从星期日开始 - 星期六

输出
此库函数提供以下输出/参数。

  • 月份全名的字符串

编码示例

-- Include/Call for this library
require("date")
print(date.num_dow_abr(6)
--Fri

name_dow_num

输入
此库函数需要以下输入/参数。

  • 给出星期几的全名
    • 从星期日开始 - 星期六

输出
此库函数提供以下输出/参数。

  • 星期几的数字

编码示例

-- Include/Call for this library
require("date")
print(date.name_dow_num("Friday")
--6

abr_dow_num

输入
此库函数需要以下输入/参数。

  • 给出星期几的缩写名称
    • 从星期日开始 - 星期六

输出
此库函数提供以下输出/参数。

  • 星期几的数字

编码示例

-- Include/Call for this library
require("date")
print(date.name_dow_num("Fri")
--6

what_tz

输入
此库函数需要以下输入/参数。

  • 无需输入

输出
此库函数提供以下输出/参数。

  • 将读取 /etc/TZ 并输出内容

编码示例

-- Include/Call for this library
require("date")
print(date.what_tz())
--great if want to do os.date() and want the timezone also. 
-- lua os.date() doesn't show the timezone

change_tz

这在未来可能会稍有变化。/etc/TZ 可能有 bug

输入
此库函数需要以下输入/参数。

  • 时区名称和偏移量的字符串
    • EST-5

输出
此库函数提供以下输出/参数。

  • 输出结果和时区是什么
    • 结果:成功或失败
    • 只是运行 what_tz 并输出

编码示例

-- Include/Call for this library
require("date")
print(date.change_tz("EST+5")) -- has to be reverse or EST-5. Still don't know why
--will output if able to write to the file and the set timezone