Difference between revisions of "Os.date"

From GiderosMobile
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Class:''' [[os]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/os|os]]<br/>
 
=== <translate>Description</translate> ===
 
<translate>Returns a string or a table containing date and time, formatted according to the given string format.
 
  
 +
=== Description ===
 +
Returns a string or a table containing date and time, formatted according to the given string format.
 +
<syntaxhighlight lang="lua">
 +
os.date(format,time)
 +
</syntaxhighlight>
  
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 the ''time'' argument is present, this is the time to be formatted, otherwise, '''date''' formats the current time.
  
 +
If ''format'' starts with '!', then the date is formatted in Coordinated Universal 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).
+
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--59)
 +
*'''wday''' (weekday, Sunday is 1)
 +
*'''yday''' (day of the year)
 +
*'''isdst''' (daylight saving flag, a boolean)
  
 +
If format is not "*t", then date returns the date as a string, formatted according to the same rules as the C function strftime:
 +
*'''%a''' - Abbreviated weekday name (eg. Wed)
 +
*'''%A''' - Full weekday name (eg. Wednesday)
 +
*'''%b''' - Abbreviated month name (eg. Sep)
 +
*'''%B''' - Full month name (eg. September)
 +
*'''%c''' - Date and time representation appropriate for locale (eg. 23/04/07 10:20:41)
 +
*'''%d''' - Day of month as decimal number (01 - 31)
 +
*'''%H''' - Hour in 24-hour format (00 - 23)
 +
*'''%I''' - Hour in 12-hour format (01 - 12)
 +
*'''%j''' - Day of year as decimal number (001 - 366)
 +
*'''%m''' - Month as decimal number (01 - 12)
 +
*'''%M''' - Minute as decimal number (00 - 59)
 +
*'''%p''' - Current locale’s A.M./P.M. indicator for 12-hour clock (eg. AM/PM)
 +
*'''%S''' - Second as decimal number (00 - 59)
 +
*'''%U''' - Week of year as decimal number, with Sunday as first day of week 1 (00 - 53)
 +
*'''%w''' - Weekday as decimal number (0 - 6; Sunday is 0)
 +
*'''%W''' - Week of year as decimal number, with Monday as first day of week 1 (00 - 53)
 +
*'''%x''' - Date representation for current locale (Standard date string)
 +
*'''%X''' - Time representation for current locale (Standard time string)
 +
*'''%y''' - Year without century, as decimal number (00 - 99)  (eg. 07)
 +
*'''%Y''' - Year with century, as decimal number (eg. 2007)
 +
*'''%Z''' - Time-zone name or abbreviation; no characters if time zone is unknown
 +
*'''%%''' - Percent sign
  
If format is not "*t", then date returns the date as a string, formatted according to the same rules as the 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")).
  
 +
=== Parameters ===
 +
'''format''': (string) format of the date<br/>
 +
'''time''': (number) time to format '''optional'''<br/>
  
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")).</translate>
+
=== Examples ===
<source lang="lua">
+
<syntaxhighlight lang="lua">
os.date(format,time)
+
local myt = os.time({year=2003, month=7, day=14, hour=8, min=10, sec=0,})
</source>
+
local myd = os.date("*t", myt)
=== <translate>Parameters</translate> ===
+
print(myd.year, myd.min, myd.sec)
'''format''': (string) <translate>format of the date</translate> <br/>
+
</syntaxhighlight>
'''time''': (number) <translate>time to format</translate> '''optional'''<br/>
+
 
 +
<syntaxhighlight lang="lua">
 +
print(os.date("today is %A, in %B")) -- today is Saturday, in October
 +
print(os.date("%x", 906000490)) -- 09/17/98
 +
 
 +
print (os.date ("%x")) --> 25/04/07
 +
print (os.date ("%c")) --> 25/04/07 10:10:05
 +
print (os.date ("%A, %m %B %Y")) --> Wednesday, 04 April 2007
 +
</syntaxhighlight>
 +
 
 +
=== See also ===
 +
[[Os.time]]
  
 
{{Os}}
 
{{Os}}

Latest revision as of 23:48, 14 October 2023

Available since: Gideros 2011.6
Class: os

Description

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

os.date(format,time)

If the time argument is present, this is the time to be formatted, 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--59)
  • wday (weekday, Sunday is 1)
  • yday (day of the year)
  • isdst (daylight saving flag, a boolean)

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

  • %a - Abbreviated weekday name (eg. Wed)
  • %A - Full weekday name (eg. Wednesday)
  • %b - Abbreviated month name (eg. Sep)
  • %B - Full month name (eg. September)
  • %c - Date and time representation appropriate for locale (eg. 23/04/07 10:20:41)
  • %d - Day of month as decimal number (01 - 31)
  • %H - Hour in 24-hour format (00 - 23)
  • %I - Hour in 12-hour format (01 - 12)
  • %j - Day of year as decimal number (001 - 366)
  • %m - Month as decimal number (01 - 12)
  • %M - Minute as decimal number (00 - 59)
  • %p - Current locale’s A.M./P.M. indicator for 12-hour clock (eg. AM/PM)
  • %S - Second as decimal number (00 - 59)
  • %U - Week of year as decimal number, with Sunday as first day of week 1 (00 - 53)
  • %w - Weekday as decimal number (0 - 6; Sunday is 0)
  • %W - Week of year as decimal number, with Monday as first day of week 1 (00 - 53)
  • %x - Date representation for current locale (Standard date string)
  • %X - Time representation for current locale (Standard time string)
  • %y - Year without century, as decimal number (00 - 99) (eg. 07)
  • %Y - Year with century, as decimal number (eg. 2007)
  • %Z - Time-zone name or abbreviation; no characters if time zone is unknown
  • %% - Percent sign

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")).

Parameters

format: (string) format of the date
time: (number) time to format optional

Examples

local myt = os.time({year=2003, month=7, day=14, hour=8, min=10, sec=0,})
local myd = os.date("*t", myt)
print(myd.year, myd.min, myd.sec)
print(os.date("today is %A, in %B")) -- today is Saturday, in October
print(os.date("%x", 906000490)) -- 09/17/98

print (os.date ("%x")) --> 25/04/07
print (os.date ("%c")) --> 25/04/07 10:10:05
print (os.date ("%A, %m %B %Y")) --> Wednesday, 04 April 2007

See also

Os.time