Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set system time zone in Linux

Tags:

c

linux

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?

like image 446
Anusha Avatar asked Oct 21 '25 06:10

Anusha


2 Answers

Use stime to set the time,and tzset to set the timezone.

Note that the tz (timezone) parameter to settimeofday is obsolete.

like image 157
Jonathon Reinhart Avatar answered Oct 22 '25 20:10

Jonathon Reinhart


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)