[Home] [Downloads] [Search] [Help/forum]

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 ) - see below for using os.setlocale to get the correct locale.
%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


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


os.setlocale ("", "time")


See Also ...

Lua functions

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

Topics

Lua base functions
Lua bc (big number) functions
Lua bit manipulation functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua math functions
Lua os functions
Lua package functions
Lua PCRE regular expression functions
Lua script extensions
Lua string functions
Lua syntax
Lua table functions
Lua utilities
Scripting
Scripting callbacks - plugins

(Help topic: lua=os.date)

Documentation contents page


Search ...

Enter a search string to find matching documentation.

Search for:   

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]