954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How do I change the system time using C on Linux?

I need to do a C program where user will be able to change the system time.

I'm looking for this at some websites, but I can't find how to solve this.

How do I change the system time using C on Linux?

Any clue?

10x

cesar7160
Newbie Poster
7 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

Are you running as root?

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

Yes, I am.

cesar7160
Newbie Poster
7 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

This is what I have:

time_t tiempovar;
        struct tm * tmdvar;
        time ( &tiempovar );
        tmdvar = localtime ( &tiempovar );
        tmdvar->tm_year = 2009 - 1900;
        tmdvar->tm_mon = 5;
        tmdvar->tm_mday = 26;

        //struct tz * tzvar;
        //settimeofday(*tmdvar, const struct timezone *tz);
cesar7160
Newbie Poster
7 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

http://www.manpagez.com/man/2/settimeofday/
The timezone is NULL, and you fill in a struct timeval and pass a pointer to it.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 
http://www.manpagez.com/man/2/settimeofday/ The timezone is NULL, and you fill in a struct timeval and pass a pointer to it.

How do I use "struct timezone" correctly?

Can you please include some code?

Thanks

cesar7160
Newbie Poster
7 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

Read the manual - it's not used, so passing NULL should work just fine.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 
Read the manual - it's not used, so passing NULL should work just fine.

I solved it.

I'll copy the code tomorrow.

cesar7160
Newbie Poster
7 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You