Garry's Mod Wiki

Revision Difference

os.date#517651

<function name="date" parent="os" type="libraryfunc"> <description>Returns the date/time as a formatted string or in a table.</description> <realm>Shared and Menu</realm> <args> <arg name="format" type="string">The format string.&#xA;&#xA;If this is equal to &#x27;*t&#x27; or &#x27;!*t&#x27; then this function will return a &lt;page&gt;DateData&lt;/page&gt;, otherwise it will return a string.&#xA;&#xA;If this starts with an &#x27;!&#x27;, the returned data will use the UTC timezone rather than the local timezone.&#xA;&#xA;See http://www.mkssoftware.com/docs/man3/strftime.3.asp for available format flags.&#xA;&#xA;&lt;bug issue=&quot;329&quot;&gt;**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.&lt;/bug&gt;</arg>⤶ <arg name="format" type="string">The format string.⤶ If this is equal to '*t' or '!*t' then this function will return a <page>DateData</page>, 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 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.</bug></arg>⤶ <arg name="time" type="number">Time to use for the format.</arg> </args> <rets> <ret name="" type="string">Formatted date <note>This will be a <page>DateData</page> if the first argument equals to '*t' or '!*t'</note></ret> </rets> </function> <example> <description> 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. </description> <code> local Timestamp = os.time() local TimeString = os.date( "%H:%M:%S - %d/%m/%Y" , Timestamp ) print( "Timestamp:", Timestamp ) print( "TimeString:", TimeString ) </code> <outputfixedwidth>Fixed width</outputfixedwidth> <output>Timestamp:&amp;#9;{{#time:U</output> <output>Timestamp:&#9;{{#time:U</output> </example> TimeString:&#9;{{#time:H:i:s - d/m/Y}} TimeString: {{#time:H:i:s - d/m/Y}} }}