lua os.time和os.data詳解


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,month,day並且可能具有字段 hour(默認為12),min(默認為0), sec(默認為0)和isdst(默認為nil)。有關這些字段的說明,請參見功能。 monthdayhourminsecisdst os.date

//2020-7-15 11:16:22
local timestamp = os.time({day=15, month=7, year=2020, hour=11, min=16, sec=22})

返回值是一個數字,其含義取決於您的系統。在POSIX,Windows和某些其他系統中,此數字用於計算從某個給定的開始時間(“時期”)起的秒數。在其它系統中,意思是未指定,並且通過返回的數字time只能用於作為參數 os.dateos.difftime

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM