| www.delorie.com/gnu/docs/octave/octave_166.html | search |
![]() Buy GNU books! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Octave's core set of functions for manipulating time values are patterned after the corresponding functions from the standard C library. Several of these functions use a data structure for time that includes the following elements:
usec
sec
min
hour
mday
mon
year
wday
yday
isdst
zone
In the descriptions of the following functions, this structure is referred to as a tm_struct.
time was 856163706.
time (or any other nonnegative
integer), to the local time and return a string of the same form as
asctime. The function ctime (time) is equivalent to
asctime (localtime (time)). For example,
ctime (time ())
=> "Mon Feb 17 01:15:06 1997"
|
gmtime (time ())
=> {
usec = 0
year = 97
mon = 1
mday = 17
sec = 6
zone = CST
min = 15
wday = 1
hour = 7
isdst = 0
yday = 47
}
|
localtime (time ())
=> {
usec = 0
year = 97
mon = 1
mday = 17
sec = 6
zone = CST
min = 15
wday = 1
hour = 1
isdst = 0
yday = 47
}
|
mktime (localtime (time ())
=> 856163706
|
asctime (localtime (time ())
=> "Mon Feb 17 01:15:06 1997\n"
|
This is equivalent to ctime (time ()).
printf. Except where noted, substituted
fields have a fixed size; numeric fields are padded if necessary.
Padding is with zeros by default; for fields that display a single
number, padding can be changed or inhibited by following the `%'
with one of the modifiers described below. Unknown field specifiers are
copied as normal characters. All other characters are copied to the
output without change. For example,
strftime ("%r (%Z) %A %e %B %Y", localtime (time ())
=> "01:15:06 AM (CST) Monday 17 February 1997"
|
Octave's strftime function supports a superset of the ANSI C
field specifiers.
Literal character fields:
%
n
t
Numeric modifiers (a nonstandard extension):
- (dash)
_ (underscore)
Time fields:
%H
%I
%k
%l
%M
%p
%r
%R
%s
%S
%T
%X
%Z
Date fields:
%a
%A
%b
%B
%c
%C
%d
%e
%D
%h
%j
%m
%U
%w
%W
%x
%y
%Y
Most of the remaining functions described in this section are not patterned after the standard C library. Some are available for compatiblity with MATLAB and others are provided because they are useful.
clock ()
=> [ 1993, 8, 20, 4, 56, 1 ]
|
The function clock is more accurate on systems that have the
gettimeofday function.
date ()
=> "20-Aug-93"
|
clock. For example:
t0 = clock (); # many computations later... elapsed_time = etime (clock (), t0); |
will set the variable elapsed_time to the number of seconds since
the variable t0 was set.
cputime returns 0 for each of its output values.
Note that because Octave used some CPU time to start, it is reasonable
to check to see if cputime works by checking to see if the total
CPU time used is nonzero.
is_leap_year will use the current year.
For example,
is_leap_year (2000)
=> 1
|
tic (); # many computations later... elapsed_time = toc (); |
will set the variable elapsed_time to the number of seconds since
the most recent call to the function tic.
If you are more interested in the CPU time that your process used, you
should use the cputime function instead. The tic and
toc functions report the actual wall clock time that elapsed
between the calls. This may include time spent processing other jobs or
doing nothing at all. For example,
tic (); sleep (5); toc ()
=> 5
t = cputime (); sleep (5); cputime () - t
=> 0
|
(This example also illustrates that the CPU timer may have a fairly coarse resolution.)
fprintf (stderr, "wait please...\n"); pause (5); clc; |
usleep will pause the execution for
round (microseconds / 1e6) seconds.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |