Difference between revisions of "Manual:DIL Manual/asctime()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
Line 1: Line 1:
−
<span id="bfasctime"></span>
+
= asctime() =
−
string asctime(i : integer)
+
'''Function''' (string). Writes a time in seconds as a date, such as "Mon Nov 18 18:49:08 1996".
−
    i : the time to convert in seconds ([[#bvrealtime|realtime]] variable)
 
  
−
    Returns: The seconds converted into an ascii format date of the following
+
  asctime(t : integer)
−
            form "Mon Nov 18 18:49:08 1996"
 
  
−
    Example:
+
Converts <code>t</code>, a real-world time in seconds since 1 January 1970 (the value of
−
      log(asctime(realtime));
+
[[Manual:DIL Manual/realtime|realtime]]), into a date and time in the server's time zone. It is
 +
the C library's <code>ctime()</code> without the newline at the end.
  
−
</PRE
+
== Parameters ==
−
<span id="bfasctime"></span>
+
{| class="wikitable"
−
string asctime(i : integer)
+
! Name !! Type !! Meaning
−
    i : the time to convert in seconds ([[#bvrealtime|realtime]] variable)
+
|-
 +
| t || integer || Seconds since 1 January 1970, usually <code>realtime</code> or a value saved from it.
 +
|}
  
−
    Returns: The seconds converted into an ascii format date of the following
+
== Returns ==
−
            form  "Mon Nov 18 18:49:08 1996"
+
String: <code>"Www Mmm dd hh:mm:ss yyyy"</code>, for instance <code>"Sat Nov 14 09:05:31 2026"</code>.
 +
It fails when the argument is a failed value.
  
−
    Example:
+
== Notes ==
−
      log(asctime(realtime));
+
* '''Give it a variable or an expression, never a bare number.''' vmc compiles
 +
  <code>asctime(0)</code> or <code>asctime(3600 * 24)</code> without its argument, and running
 +
  that stops the server. <code>asctime(realtime)</code>, <code>asctime(t)</code> or
 +
  <code>asctime(pc.birth)</code> are fine.
 +
* DIL integers are 32 bits, so dates after January 2038 can't be shown.
 +
* For the time in the game world use [[Manual:DIL Manual/mudhour()|mudhour()]],
 +
  [[Manual:DIL Manual/mudday()|mudday()]] and the like.
  
−
</PRE
+
== Example ==
 +
<pre>
 +
dilbegin bug_note(pc : unitptr, txt : string);
 +
var
 +
  i : integer;
 +
code
 +
{
 +
  i := flog("bugs", pc.name + " " + asctime(realtime) + ": " + txt + "<br/>", "a");
 +
  sendtext("Thank you, it is noted.<br/>", pc);
 +
  quit;
 +
}
 +
dilend
 +
</pre>
 +
Writes a player's report with the date and time into a log file, as the <code>bug</code>
 +
command in commands.zon does.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/realtime|realtime]]
 +
* [[Manual:DIL Manual/birth|birth]]
 +
* [[Manual:DIL Manual/flog()|flog()]]
 +
* [[Manual:DIL Manual/log()|log()]]

Revision as of 23:20, 14 November 2026

asctime()

Function (string). Writes a time in seconds as a date, such as "Mon Nov 18 18:49:08 1996".

asctime(t : integer)

Converts t, a real-world time in seconds since 1 January 1970 (the value of realtime), into a date and time in the server's time zone. It is the C library's ctime() without the newline at the end.

Parameters

Name Type Meaning
t integer Seconds since 1 January 1970, usually realtime or a value saved from it.

Returns

String: "Www Mmm dd hh:mm:ss yyyy", for instance "Sat Nov 14 09:05:31 2026". It fails when the argument is a failed value.

Notes

  • Give it a variable or an expression, never a bare number. vmc compiles
 asctime(0) or asctime(3600 * 24) without its argument, and running
 that stops the server. asctime(realtime), asctime(t) or
 asctime(pc.birth) are fine.
  • DIL integers are 32 bits, so dates after January 2038 can't be shown.
  • For the time in the game world use mudhour(),
 mudday() and the like.

Example

dilbegin bug_note(pc : unitptr, txt : string);
var
   i : integer;
code
{
   i := flog("bugs", pc.name + " " + asctime(realtime) + ": " + txt + "<br/>", "a");
   sendtext("Thank you, it is noted.<br/>", pc);
   quit;
}
dilend

Writes a player's report with the date and time into a log file, as the bug command in commands.zon does.

See also