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?
Use stime to set the time,and tzset to set the timezone.
Note that the tz (timezone) parameter to settimeofday is obsolete.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With