Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - English

Change language to:
Français - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2024.1.0. This page might be outdated.
See the recommended documentation of this function

Scilab Help >> Time and Date > realtimeinit


sets the time unit


sets the initial datetime and starts the chronometer, or waits until a given datetime





positive decimal number: time unit duration, in seconds.


decimal number: initial datetime, in time_unit. This meaning holds when realtime(…) is called for the first time after the last realtimeinit(…). This first call sets the datetime origin and restarts the real timer.


decimal number: datetime up to which Scilab must wait before performing the next instruction, expressed in time unit.


While sleep(d) waits for a given fixed duration, realtime(t) will wait the required (unknown) time to reach the given datetime t.

realtimeinit(time_unit) defines the time unit in which the datetime t specified by realtime is expressed.

After calling realtimeinit(time_unit), the first call to realtime(t0) sets the current datetime to t0, without any wait. Each new call to realtime(t) then waits till datetime t is reached. If t is already passed, no wait is added.


In the following example, in a loop, a job takes an arbitrary time, from 0 to 1.50 s. This is simulated with a sleep() of random duration. Although this period is not regular, realtime() is used to compensate and print something every 2.00 seconds:

for k = 1:10
    if k==1, mprintf("\nSleep for  Wake-up at   Wait until date\n"), end
    d = rand(1,1);
    mprintf(' %4.2f s     %5.2f s', d*1.5, toc());
    mprintf('      %5.2f s\n', toc());
Sleep for  Wake-up at   Wait until date
 0.28 s      0.57 s       2.08 s
 0.03 s      2.11 s       4.08 s
 1.27 s      5.34 s       6.08 s
 0.11 s      6.19 s       8.08 s
 1.28 s      9.36 s      10.08 s
 0.02 s     10.10 s      12.08 s
 0.28 s     12.36 s      14.08 s
 0.74 s     14.82 s      16.08 s
 1.12 s     17.20 s      18.08 s
 1.41 s     19.49 s      20.08 s

See also

  • sleep — suspend all code executions (console, scripts, callbacks,..)
  • getdate — get date and time information
  • waitbar — Draw a waitbar
  • progressionbar — Draw a progression bar
Report an issue
<< now Time and Date sleep >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:49:21 CET 2020