Setting Time in C

J

Jimmy

Hello,

Can anyone tell me how to set the time using C code? After browsing through
MSDN, I only find the C command to get time and not set time. Can anyone
advise me on this??
 
P

Pushkar Pradhan

I believe you want to set system time, right?
There is settimeofday() similar to gettimeofday().
But it says you have to be the system administrator to do that, else it
will fail.
 
M

Mike Wahler

Pushkar Pradhan said:
I believe you want to set system time, right?
There is settimeofday() similar to gettimeofday().

C has no such functions.

But it says you have to be the system administrator to do that, else it
will fail.

C has no concept of 'system administrator'.

Please keep platform-specific issues out of this
ISO standard C language group.

-Mike
 
M

Mike Wahler

Jimmy said:
Hello,

Can anyone tell me how to set the time using C code?

There is no way. C does not require the host platform
to have a clock at all.
After browsing through
MSDN,


MSDN does not define or document the C language, but
Microsoft products.
I only find the C command

C has no commands.
to get time and not set time. Can anyone
advise me on this??

The C standard library provides a function called
'time()' which can retrieve a system clock's time
*if* such a system clock exists. There is no
C function which can alter the state of a system's
clock.

You'll need platform-specific tools. You mention MSDN.
If you're wanting to do this on a Windows system, then
yes, there are indeed Microsoft functions for accessing
and modifying the state of the system clock.

But platform specific issues are not topical here.
The answer is indeed there at the MSDN site, all
you have to do is look. It's also described in the
documentation of the Windows API, provided with
virtually all Windows compilers.

-Mike
 
J

Jimmy

Thanks

--
Regards

Jimmy Lim

Mike Wahler said:
There is no way. C does not require the host platform
to have a clock at all.



MSDN does not define or document the C language, but
Microsoft products.


C has no commands.


The C standard library provides a function called
'time()' which can retrieve a system clock's time
*if* such a system clock exists. There is no
C function which can alter the state of a system's
clock.

You'll need platform-specific tools. You mention MSDN.
If you're wanting to do this on a Windows system, then
yes, there are indeed Microsoft functions for accessing
and modifying the state of the system clock.

But platform specific issues are not topical here.
The answer is indeed there at the MSDN site, all
you have to do is look. It's also described in the
documentation of the Windows API, provided with
virtually all Windows compilers.

-Mike
 
D

Dan Pop

In said:
Can anyone tell me how to set the time using C code? After browsing through
MSDN, I only find the C command to get time and not set time. Can anyone
advise me on this??

The C language has no facility for doing this. Your OS's API probably
provides a way of doing it. Your reference to MSDN suggests that
comp.os.ms-windows.programmer.win32 is the right newsgroup for asking.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top