<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.spheredev.org/index.php?action=history&amp;feed=atom&amp;title=Legacy%3AGetSeconds</id>
		<title>Legacy:GetSeconds - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.spheredev.org/index.php?action=history&amp;feed=atom&amp;title=Legacy%3AGetSeconds"/>
		<link rel="alternate" type="text/html" href="http://wiki.spheredev.org/index.php?title=Legacy:GetSeconds&amp;action=history"/>
		<updated>2026-05-13T19:50:01Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.29.0</generator>

	<entry>
		<id>http://wiki.spheredev.org/index.php?title=Legacy:GetSeconds&amp;diff=9899&amp;oldid=prev</id>
		<title>Bruce Pascoe at 06:40, 30 June 2015</title>
		<link rel="alternate" type="text/html" href="http://wiki.spheredev.org/index.php?title=Legacy:GetSeconds&amp;diff=9899&amp;oldid=prev"/>
				<updated>2015-06-30T06:40:24Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 06:40, 30 June 2015&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Obtains the amount of time in seconds, in floating point, elapsed since an arbitrary time. This function typically has sub-microsecond precision, making it useful for benchmarking or any other situation where you need higher-precision timing than [[API:GetTime|GetTime]]() can give you. A Sphere 2.0 engine such as [[minisphere]] is required to use this function.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Obtains the amount of time in seconds, in floating point, elapsed since an arbitrary time. This function typically has sub-microsecond precision, making it useful for benchmarking or any other situation where you need higher-precision timing than [[API:GetTime|GetTime]]() can give you. A &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;'''&lt;/ins&gt;Sphere 2.0&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;''' &lt;/ins&gt;engine such as [[minisphere]] is required to use this function.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Usage==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Usage==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l17&quot; &gt;Line 17:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 17:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;// Code that needs to be timed&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;// Code that needs to be timed&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;// ...&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;// ...&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;var duration = &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;GetTime&lt;/del&gt;() - start_time;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;var duration = &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;GetSeconds&lt;/ins&gt;() - start_time;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Bruce Pascoe</name></author>	</entry>

	<entry>
		<id>http://wiki.spheredev.org/index.php?title=Legacy:GetSeconds&amp;diff=9898&amp;oldid=prev</id>
		<title>Bruce Pascoe: Created page with &quot;Obtains the amount of time in seconds, in floating point, elapsed since an arbitrary time. This function typically has sub-microsecond precision, making it useful for benchmar...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wiki.spheredev.org/index.php?title=Legacy:GetSeconds&amp;diff=9898&amp;oldid=prev"/>
				<updated>2015-06-30T06:38:43Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;Obtains the amount of time in seconds, in floating point, elapsed since an arbitrary time. This function typically has sub-microsecond precision, making it useful for benchmar...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Obtains the amount of time in seconds, in floating point, elapsed since an arbitrary time. This function typically has sub-microsecond precision, making it useful for benchmarking or any other situation where you need higher-precision timing than [[API:GetTime|GetTime]]() can give you. A Sphere 2.0 engine such as [[minisphere]] is required to use this function.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
{{Usage|returns=number|func=GetSeconds}}&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
var time = GetSeconds();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above gets the number of seconds passed since some predetermined time, and places it in the &amp;lt;var&amp;gt;time&amp;lt;/var&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
var start_time = GetSeconds();&lt;br /&gt;
// Code that needs to be timed&lt;br /&gt;
// ...&lt;br /&gt;
var duration = GetTime() - start_time;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above example will find out how long a particular piece of code runs for.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
var done = false;&lt;br /&gt;
var fps = GetFrameRate();&lt;br /&gt;
var updates_performed = 0;&lt;br /&gt;
var start_time = GetSeconds();&lt;br /&gt;
while (!done)&lt;br /&gt;
{&lt;br /&gt;
  while (updates_performed &amp;lt; (GetSeconds() - start_time) * fps)&lt;br /&gt;
  {&lt;br /&gt;
    // Update game here&lt;br /&gt;
    // ...&lt;br /&gt;
    updates_performed++;&lt;br /&gt;
  }&lt;br /&gt;
  // Draw the game screen here&lt;br /&gt;
  // ...&lt;br /&gt;
  FlipScreen();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above example is one way to regulate the speed of a Sphere game inside a JavaScript loop. The game code will have to be separated into updates (player input processing, moving entities, checking collisions, etc.) and drawing (drawing sprites, the map, score, etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
var FPS = 60;                // The desired FPS&lt;br /&gt;
var delayTime = 1.0/FPS;     // The time between frames&lt;br /&gt;
var lastTime = GetSeconds(); // The time of the last frame&lt;br /&gt;
while(loopCondition)         // While we should continue looping&lt;br /&gt;
{&lt;br /&gt;
  if(GetSeconds() &amp;gt; lastTime + delayTime) // If enough time has elapsed&lt;br /&gt;
  {&lt;br /&gt;
    lastTime = GetSeconds(); // Record the time of this frame&lt;br /&gt;
    doStuff();               // Do your stuff&lt;br /&gt;
  }&lt;br /&gt;
  drawStuff();               // Draw your stuff&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example is an alternative to the one above. Obviously, doStuff() and drawStuff() will correspond with functions that actually process the game logic and draw the game state respectively.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
*	The starting time can be assumed to be constant throughout the running of a game. Thus GetSeconds() is very useful as a tool to pace JavaScript loops, which would normally run at different speeds on different systems.&lt;br /&gt;
*	Core JavaScript provides a similar mechanism via the [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date Date] object's [https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/getTime Date.getTime]() method. This counter, if used with a Date object that reflects the current time, displays the number of milliseconds since midnight 01 January, 1970 UTC. Refer to the links for more information.&lt;br /&gt;
*	Unlike [[API:GetTime|GetTime]](), the value returned by this function is not subject to wraparound.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*	[[API:FlipScreen|FlipScreen]]()&lt;br /&gt;
*	[[API:GetFrameRate|GetFrameRate]]()&lt;br /&gt;
*	Core JavaScript [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date Date] object&lt;br /&gt;
*	Core JavaScript [https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/getTime Date.getTime]()&lt;br /&gt;
&lt;br /&gt;
{{API:Script/navbox}}&lt;/div&gt;</summary>
		<author><name>Bruce Pascoe</name></author>	</entry>

	</feed>