os.date
Lua function

os.date

Summary

Formats a date/time string

Prototype

s = os.date (format, time)



Description

Returns a string with the date and time formatted according to the format given. If no time is supplied defaults to the current time.

The format string can consist of "*t" on its own, or literal strings, mixed with the following directives:


%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)
         (Standard date and time string )
%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 you use "*t" you get a table consisting of:


  • sec (0 to 59)
  • min (0 to 59)
  • hour (0 to 23)
  • day (1 to 31)
  • month (1 to 12)
  • year (1900 onwards)
  • wday (Sunday is 1, Monday is 2 etc.)
  • yday (January 1st is 1, etc.)
  • isdst (true if Daylight Savings Time)


Examples:


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

t = os.date ("*t") --> produces a table like this:

  t.sec=18
  t.min=13
  t.hour=10
  t.day=25
  t.month=4
  t.year=2007
  t.wday=4
  t.yday=115
  t.isdst=false


Locate note - it seems that doing this helps set the locale appropriately:


os.setlocale ("", "time")



See Also ...

Topics

DOC_lua_base Lua base functions
DOC_lua_bc Lua bc (big number) functions
DOC_lua_bit Lua bit manipulation functions
DOC_lua_coroutines Lua coroutine functions
DOC_lua_debug Lua debug functions
DOC_lua_io Lua io functions
DOC_lua_math Lua math functions
DOC_lua_os Lua os functions
DOC_lua_package Lua package functions
DOC_lua_rex Lua PCRE regular expression functions
DOC_lua Lua script extensions
DOC_lua_string Lua string functions
DOC_lua_tables Lua table functions
DOC_lua_utils Lua utilities
DOC_scripting Scripting

Lua functions

LUA_os.clock os.clock (Amount of CPU time used)
LUA_os.difftime os.difftime (Calculates a time difference in seconds)
LUA_os.execute os.execute (Executes an operating system command)
LUA_os.exit os.exit (Attempts to terminate the process)
LUA_os.getenv os.getenv (Returns an operating system environment variable)
LUA_os.remove os.remove (Deletes a file)
LUA_os.rename os.rename (Renames a file)
LUA_os.setlocale os.setlocale (Sets the current locale to the supplied locale)
LUA_os.time os.time (Returns the current time or calculates the time in seconds from a table)
LUA_os.tmpname os.tmpname (Returns a name for a temporary file)

(Help topic: lua=os.date)

DOC_contents Documentation contents page