Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/clock_settime.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/clock_settime.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/clock_settime.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/clock_settime.html on line 8
Set a clock
#include <time.h>
int clock_settime( clockid_t id,
const struct timespec * tp );
- id
- The clock ID, CLOCK_REALTIME or
CLOCK_MONOTONIC,
that maintains the system time, or the clock ID that's returned by
ClockId().
- tp
- A pointer to a
timespec
structure containing at least the following members:
- tv_sec — the number of seconds since 1970.
- tv_nsec — the number of nanoseconds in the current
second.
This value increases by some multiple of nanoseconds, based on the
system clock's resolution.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The clock_settime() function sets the clock specified by
id to the time specified in the buffer pointed to by
tp.
|
- Be careful if you set the date during the period that a time zone is
switching from
daylight saving time (DST) to standard time.
When a time zone changes to standard time, the local time goes back one hour
(for
example, 2:00 a.m. becomes 1:00 a.m.).
The local time during this hour is ambiguous (e.g. 1:14 a.m. occurs twice
in the morning that the time zone switches to standard time).
To avoid problems, use UTC time to set the date in this period.
- You can't set the time when the id is
CLOCK_MONOTONIC.
- You need to have superuser privileges to set the clock.
|
- 0
- Success
- -1
- An error occurred
(errno
is set).
- EINVAL
- Invalid id or the number of nanoseconds specified
by the tv_nsec is less than zero or greater than or equal to 1000 million.
- EPERM
- You don't have sufficient privilege to change the time.
/* This program sets the clock forward 1 day. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int main( void )
{
struct timespec stime;
if( clock_gettime( CLOCK_REALTIME, &stime) == -1 ) {
perror( "getclock" );
return EXIT_FAILURE;
}
stime.tv_sec += (60*60)*24L; /* Add one day */
stime.tv_nsec = 0;
if( clock_settime( CLOCK_REALTIME, &stime) == -1 ) {
perror( "setclock" );
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
POSIX 1003.1 TMR
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |
clock_getres(),
clock_gettime(),
errno,
timespec
Clocks, Timers, and Getting a Kick Every So Often
chapter of Getting Started with QNX Neutrino
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/clock_settime.html on line 226
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/clock_settime.html on line 226