Difference between revisions of "Os.date"

From GiderosMobile
 
Line 11: Line 11:
 
If the ''time'' argument is present, this is the time to be formatted, 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:
 
After this optional character, if format is the string '''"*t"''', then date returns a table with the following fields:

Latest revision as of 22: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