Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用C在linux中指定时区_C_Linux_Unix_Epoch - Fatal编程技术网

如何使用C在linux中指定时区

如何使用C在linux中指定时区,c,linux,unix,epoch,C,Linux,Unix,Epoch,我试图设置系统的时区,并试图使用settimeofday(),它将时区结构作为参数,但刚刚读到该结构现在已过时(),我怎么能这样做呢 提前谢谢 编辑:啊,我觉得自己很愚蠢 我创建了一个link.c并编译了它: #include <stdio.h> void main() { printf("This is the link \n"); } #include <stdio.h> void main() { printf("This is the tar

我试图设置系统的时区,并试图使用settimeofday(),它将时区结构作为参数,但刚刚读到该结构现在已过时(),我怎么能这样做呢

提前谢谢

编辑:啊,我觉得自己很愚蠢

我创建了一个link.c并编译了它:

#include <stdio.h>

void main()
{
    printf("This is the link \n");
}
#include <stdio.h>

void main()
{
    printf("This is the target \n");
}
#包括
void main()
{
printf(“这是链接”);
}
创建了target.c,并对其进行了编译:

#include <stdio.h>

void main()
{
    printf("This is the link \n");
}
#include <stdio.h>

void main()
{
    printf("This is the target \n");
}
#包括
void main()
{
printf(“这是目标\n”);
}
然后在测试程序中尝试符号链接功能:

#include <unistd.h>

void main()
{
    int garbage = symlink("/home/imandhan/pythonTests/link", "/home/imandhan/pythonTests/target");
    printf(garbage);
}
#包括
void main()
{
int garbage=symlink(“/home/imandhan/pythonTests/link”,“/home/imandhan/pythonTests/target”);
printf(垃圾);
}
出于某种原因,这给了我一个分段错误。我做错什么了吗

有关设置应用程序时区的信息,请参阅


对于整个系统-symlink
/etc/localtime
/usr/share/zoneinfo/

下的相应文件,对于单个会话/用户,设置
TZ
环境变量。感谢您的回复。只是为了确保我得到它。。。我想用C语言为整个系统设置时区,所以我需要找到一些方法将/etc/localtime符号链接到/usr/share/zoneinfo下的文件,对吗?使用tzset()不起作用。。对不起,我是linux新手,在我的工作系统上没有管理员权限来尝试弄乱系统。啊,我觉得自己真的很愚蠢。我创建了一个link.c并编译它:#include void main(){printf(“这是链接”)}创建了一个target.c,并编译它:#include void main(){printf(“这是目标”);},然后在测试程序中尝试了symlink函数:#include void main(){int garbage=symlink(“/home/imandhan/pythonTests/link”,“/home/imandhan/pythonTests/target”);printf(垃圾);}出于某种原因,这给了我一个分段错误。我做错了什么吗?你为什么这么做?系统管理是通过命令行和精心编制的脚本完成的,而不是通过C。哦,对了。返回-1。我的符号链接语法错了吗?嗯,是为了实习,他们想让我为视频会议设备编写这些函数,而不是在我根据传递给函数的结构设置时间、时区和其他内容之前。我还没有完全了解全局,因为我刚刚开始。@iman453检查errno以了解具体的错误。@Vitor哦,我不知道errno是什么。这非常有用!谢谢。我做错的事情是我已经用链接创建了一个文件名称