当前位置:Linux教程 - Linux文化 - linux下C编程有没有获取系统当前时间的函数?

linux下C编程有没有获取系统当前时间的函数?


>>> 此贴的回复 >> man gettimeofday

改IP的话.用ioctl的方式.

CODE:[Copy to clipboard]int set_dev_ip(char *ip,char *ethname) { struct ifreq ifreq; struct protoent *pro; struct sockaddr_in ipaddr; int sockfd;

pro=getprotobyname("tcp"); if((sockfd=socket(AF_INET,SOCK_STREAM,pro->p_proto)) time_t tp; char str; time(&tp); 获得1970年1月1日到现在的秒数,一个很大的值 str=ctime(&tp); 将秒数转为可以阅读的字符串

>>> 此贴的回复 >> 可以用 localtime 函数分别获取年月日时分秒的数值。

CODE:[Copy to clipboard]#include #include

int main() { time_t now; now = time(0); tm *tnow = localtime(&now); printf("%d %d %d %d %d %d\n", 1900+tnow->tm_year, tnow->tm_mon+1, tnow->tm_mday, tnow->tm_hour, tnow->tm_min, tnow->tm_sec); }

>>> 此贴的回复 >> 参考资料: http://fanqiang.chinaunix.net/a4/b8/20010527/201001267.html