码迷,mamicode.com
首页 > 其他好文 > 详细

lua os.time和os.data详解

时间:2020-07-14 12:59:15      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:ems   repr   date()   rsa   函数   for   strftime   use   option   

os.date ([format [, time]])

Returns a string or a table containing date and time, formatted according to the given string format.

If the time argument is present, this is the time to be formatted (see the os.time function for a description of this value). Otherwise, date formats the current time.

If format starts with ‘!‘, then the date is formatted in Coordinated Universal Time. After this optional character, if format is the string "*t", then date returns a table with the following fields: year (four digits), month (1–12), day (1–31), hour (0–23), min (0–59), sec (0–61), wday (weekday, Sunday is 1), yday (day of the year), and isdst (daylight saving flag, a boolean). This last field may be absent if the information is not available.

If format is not "*t", then date returns the date as a string, formatted according to the same rules as the ISO C function strftime.

When called without arguments, date returns a reasonable date and time representation that depends on the host system and on the current locale (that is, os.date() is equivalent to os.date("%c")).

On non-Posix systems, this function may be not thread safe because of its reliance on C function gmtime and C function localtime.

翻译: 

返回字符串或包含日期和时间的表,并根据给定的string进行格式化format如果time存在自变量,那么这是要格式化的时间(os.time有关此值的说明,请参见函数)。否则,date格式化当前时间。如果format以“ !” 开头,则日期采用世界标准时间格式。在此可选字符之后,如果format字符串“ *t” 是字符串,则date返回包含以下字段的表:( year四位数字),month(1–12),day(1–31), hour(0–23),min(0–59),sec(0-61), wday(工作日,星期日是1), yday(一年中的某天)和isdst(夏令时标志,一个布尔值)。如果信息不可用,则最后一个字段可能不存在。如果format不是“ *t”,然后date返回日期字符串,按相同的规则ISO C函数的格式strftime。在不带参数的情况下调用时, date将返回一个合理的日期和时间表示形式,该表示形式取决于主机系统和当前的语言环境(即,os.date()等效于os.date("%c"))。

os.time ([table])

Returns the current time when called without arguments, or a time representing the date and time specified by the given table. This table must have fields yearmonth, and day, and may have fields hour (default is 12), min (default is 0), sec (default is 0), and isdst (default is nil). For a description of these fields, see the os.date function.

The returned value is a number, whose meaning depends on your system. In POSIX, Windows, and some other systems, this number counts the number of seconds since some given start time (the "epoch"). In other systems, the meaning is not specified, and the number returned by time can be used only as an argument to os.date and os.difftime.

翻译:

不带参数调用时返回当前时间,或者表示给定表指定的日期和时间的时间。该表必须具有,,和字段year并且可能具有字段 (默认为12), (默认为0), (默认为0)和(默认为nil)。有关这些字段的说明,请参见功能。 monthdayhourminsecisdstos.date

返回值是一个数字,其含义取决于您的系统。在POSIX,Windows和某些其他系统中,此数字用于计算从某个给定的开始时间(“时期”)起的秒数。在其它系统中,意思是未指定,并且通过返回的数字time只能用于作为参数 os.dateos.difftime

local nowtime = os.date("*t", os.time())
for k,v in pairs(nowtime) do
    print(k,v)
end

技术图片

lua os.time和os.data详解

标签:ems   repr   date()   rsa   函数   for   strftime   use   option   

原文地址:https://www.cnblogs.com/still-smile/p/13298243.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!