Garry's Mod Wiki

os.date

string os.date( string format, number time )

Description

Returns the date/time as a formatted string or in a table.

Arguments

1 string format
The format string.

If this is equal to '*t' or '!*t' then this function will return a Structures/DateData, otherwise it will return a string.

If this starts with an '!', the returned data will use the UTC timezone rather than the local timezone.

See http://www.mkssoftware.com/docs/man3/strftime.3.asp for available format flags.

Not all flags are available on all operating systems and the result of using an invalid flag is undefined. This currently crashes the game on Windows. Most or all flags are available on OS X and Linux but considerably fewer are available on Windows. See http://msdn.microsoft.com/en-us/library/fe06s4ak.aspx for a list of available flags on Windows. Note that the # flags also crashes the game on Windows.
2 number time
Time to use for the format.

Returns

1 string
Formatted date

This will be a Structures/DateData if the first argument equals to '*t' or '!*t'

Example

This will use the os.time() function, and return it in a friendly way. os.time() is useful for storing as a date stamp but needs this to make it readable.

local Timestamp = os.time() local TimeString = os.date( "%H:%M:%S - %d/%m/%Y" , Timestamp ) print( "Timestamp:", Timestamp ) print( "TimeString:", TimeString )
Output: Timestamp: 1581691801 TimeString: 14:50:01 - 14/02/2020

Page Links


Special Pages


Wikis

?

Render Time: 31ms

Session 0
DB GetPage 4
Generate Html 3
SaveChanges 9
Render Body 0
Render Sidebar 12