Are there any functions in C language to set system time in Linux? I have to set my system time zone also. I other words, if my timezone is IST, can I set it to UTC?
Asked
Active
Viewed 8,232 times
3
-
Look at `hwclock` source code. – ymn Jun 20 '13 at 06:03
-
possible duplicate of [How can I set the time zone before calling strftime?](http://stackoverflow.com/questions/1620188/how-can-i-set-the-time-zone-before-calling-strftime) – devnull Jun 20 '13 at 06:08
3 Answers
3
Use stime
to set the time,and tzset
to set the timezone.
Note that the tz
(timezone) parameter to settimeofday
is obsolete.

Jonathon Reinhart
- 132,704
- 33
- 254
- 328
2
The default time zone, used by processes that don't have a TZ
variable in their environment, is decided by the contents of /etc/localtime
. Find the time zone you want in /usr/share/zoneinfo
and copy or symlink it.
rm /etc/localtime
ln -s /usr/share/zoneinfo/Etc/GMT /etc/localtime
There are some interactive tools to help you pick a time zone, but they vary by distribution (e.g. Debian's dpkg-reconfigure tzdata
)
1
You can set the timezone by using this
setenv("TZ", "PST8PDT", 1);
tzset();

network-programmer
- 69
- 1
- 1
- 10