函数:os.time 格式化时间
函数名称:格式化时间
函数功能:将时间转成时间戳,返回自 1970-01-01 00:00:00 UTC 起的秒数(整数)
函数方法
exampletime = os.time(timeout)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| timeout | table | 否 | 指定格式化的时间, 不写默认为当前时间 |
timeout 参数介绍
| 格式符 | 类型 | 说明 |
|---|---|---|
| hour | number | 小时 |
| min | number | 分钟 |
| wday | number | 星期 |
| day | number | 日期 |
| month | number | 月份 |
| year | number | 年 |
| sec | number | 秒 |
| yday | number | 一年当中第几天 |
| isds | boolean | 夏时令 |
| 返回值 | 类型 | 说明 |
|---|---|---|
| exampletime | number | 转换后的秒级时间戳 |
说明
时间戳通常是指一个特定时间点相对于某个特定起始时间的表示,通常以秒为单位。它是一个数字,表示从某个固定的起始时间(通常是1970年1月1日UTC,也称为UNIX纪元)到特定时间的经过的秒数。
函数示例
--获取当前时间的时间戳
local exampletime = os.time();
dialog("转换后的时间戳:"..exampletime)
dialog(os.date("%c",exampletime))
local exampletime = os.time({year=2020,month=12,day=25,hour=8,min=0,sec=0})
dialog("转换后的时间戳:"..exampletime)
dialog(os.date("%c",exampletime))