os/date

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Minor tweaks about !*t and added DateData links)
 
Line 15: Line 15:
 
See http://www.mkssoftware.com/docs/man3/strftime.3.asp for available format flags.
 
See http://www.mkssoftware.com/docs/man3/strftime.3.asp for available format flags.
  
{{Bug|Issue=3438|'''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.}}
+
{{Bug|Issue=329|'''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.}}
 
}}
 
}}
 
{{Arg
 
{{Arg

Latest revision as of 19:50, 26 May 2019

 os.date( )

Contents

Description

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

Arguments

string format

The format string.

If this is equal to '*t' or '!*t' then this function will return a DateData structure, 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.

BUG

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.

Issue Tracker: #329

Arguments

number time

Time to use for the format.

Returns

string

Formatted date

NOTE

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

Examples

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:	1568740404
TimeString:	17:13:24 - 17/09/2019
Personal tools
Navigation