歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> Linux文化 >> linux下C編程有沒有獲取系統當前時間的函數?

linux下C編程有沒有獲取系統當前時間的函數?

日期:2017/2/27 12:09:16   编辑:Linux文化

>>> 此貼的回復 >> 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


Copyright © Linux教程網 All Rights Reserved