Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify timezone in linux using C

Tags:

c

linux

unix

epoch

I was trying to set the timezone of my system, and was trying to use settimeofday(), which takes a timezone struct as an argument, but just read that that struct is now obsolete (http://linux.about.com/library/cmd/blcmdl2_settimeofday.htm) How could I go about doing this?

Thanks in advance.

EDIT: Ugh, I feel really stupid.

I created a link.c and compiled it:

#include <stdio.h>

void main()
{
    printf("This is the link \n");
}

Created a target.c, and compiled it:

#include <stdio.h>

void main()
{
    printf("This is the target \n");
}

and then tried the symlink function in a test program:

#include <unistd.h>

void main()
{
    int garbage = symlink("/home/imandhan/pythonTests/link", "/home/imandhan/pythonTests/target");
    printf(garbage);
}

This gives me a segmentation fault for some reason. Am I doing something wrong?

like image 535
iman453 Avatar asked Dec 31 '25 22:12

iman453


1 Answers

See tzset(3) for setting timezone for an application.

For the whole system - symlink /etc/localtime to appropriate file under /usr/share/zoneinfo/.

like image 54
Nikolai Fetissov Avatar answered Jan 03 '26 10:01

Nikolai Fetissov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!