zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    ubuntu16.04解决播放swf视频文件问题
    ubuntu下设置clion是使用clang和clang++
    Linux 下没有conio.h 已解决
    适合最新版docker自定义启动配置
    nginx限制ip并发数
    nginx 403错误
    ubuntu 支持中文
    CentOS 5 上使用yum同时安装32位和64位包的解决方法
    rhel yum报错
    因为swap分区无法启动
  • 原文地址:https://www.cnblogs.com/still-smile/p/13298243.html
Copyright © 2011-2022 走看看