<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Virelox</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Virelox"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Virelox"/>
	<updated>2026-05-13T18:02:17Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=FormatDate&amp;diff=54740</id>
		<title>FormatDate</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=FormatDate&amp;diff=54740"/>
		<updated>2018-04-15T10:33:11Z</updated>

		<summary type="html">&lt;p&gt;Virelox: &amp;quot;i&amp;quot; is hour not &amp;quot;m&amp;quot; on example&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Useful Function}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This function formats a date according to the given format string.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;string FormatDate( string theFormat, [ string escaper = &amp;quot;'&amp;quot;, int timestamp = GetTimestamp() ] )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
* '''theFormat''': Format string that determines how the date should be formatted. It provides the following wildcards:&lt;br /&gt;
** d: day (01-31)&lt;br /&gt;
** h: hour (00-23)&lt;br /&gt;
** i: minute (00-59)&lt;br /&gt;
** m: month (01-12)&lt;br /&gt;
** s: second (00-59)&lt;br /&gt;
** w: shortened day of the week (Su-Mo)&lt;br /&gt;
** W: day of the week (Sunday-Monday)&lt;br /&gt;
** y: shortened year (e.g. 09)&lt;br /&gt;
** Y: year (e.g. 2009)&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
{{OptionalArg}}&lt;br /&gt;
* '''escaper''': Escape character that determines the beginning or end of a non-format-area, where the wildcards aren't replaced with their corresponding value. Note that the escapers get lost.&lt;br /&gt;
* '''timestamp''': Timestamp of the date that should be formatted.&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns a string containing the formatted date.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
{{RequiredFunctions|Check}}&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server- and/or clientside Script&amp;quot; class=&amp;quot;both&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local gWeekDays = { &amp;quot;Sunday&amp;quot;, &amp;quot;Monday&amp;quot;, &amp;quot;Tuesday&amp;quot;, &amp;quot;Wednesday&amp;quot;, &amp;quot;Thursday&amp;quot;, &amp;quot;Friday&amp;quot;, &amp;quot;Saturday&amp;quot; }&lt;br /&gt;
function FormatDate(format, escaper, timestamp)&lt;br /&gt;
	Check(&amp;quot;FormatDate&amp;quot;, &amp;quot;string&amp;quot;, format, &amp;quot;format&amp;quot;, {&amp;quot;nil&amp;quot;,&amp;quot;string&amp;quot;}, escaper, &amp;quot;escaper&amp;quot;, {&amp;quot;nil&amp;quot;,&amp;quot;string&amp;quot;}, timestamp, &amp;quot;timestamp&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	escaper = (escaper or &amp;quot;'&amp;quot;):sub(1, 1)&lt;br /&gt;
	local time = getRealTime(timestamp)&lt;br /&gt;
	local formattedDate = &amp;quot;&amp;quot;&lt;br /&gt;
	local escaped = false&lt;br /&gt;
&lt;br /&gt;
	time.year = time.year + 1900&lt;br /&gt;
	time.month = time.month + 1&lt;br /&gt;
	&lt;br /&gt;
	local datetime = { d = (&amp;quot;%02d&amp;quot;):format(time.monthday), h = (&amp;quot;%02d&amp;quot;):format(time.hour), i = (&amp;quot;%02d&amp;quot;):format(time.minute), m = (&amp;quot;%02d&amp;quot;):format(time.month), s = (&amp;quot;%02d&amp;quot;):format(time.second), w = gWeekDays[time.weekday+1]:sub(1, 2), W = gWeekDays[time.weekday+1], y = tostring(time.year):sub(-2), Y = time.year }&lt;br /&gt;
	&lt;br /&gt;
	for char in format:gmatch(&amp;quot;.&amp;quot;) do&lt;br /&gt;
		if (char == escaper) then escaped = not escaped&lt;br /&gt;
		else formattedDate = formattedDate..(not escaped and datetime[char] or char) end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return formattedDate&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example outputs the actual date to a joining player.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- get the root element&lt;br /&gt;
local _root = getRootElement()&lt;br /&gt;
-- define the onPlayerJoin handler function&lt;br /&gt;
function OnPlayerJoin()&lt;br /&gt;
    -- output the formatted date&lt;br /&gt;
    outputChatBox(FormatDate(&amp;quot;'You joined our server on' m/d/Y at h:i.&amp;quot;))&lt;br /&gt;
end&lt;br /&gt;
-- add the event handler&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, _root, OnPlayerJoin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Author: NeonBlack&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>Virelox</name></author>
	</entry>
</feed>