linux c语言每天的0~12:00随机执行操作
生活随笔
收集整理的這篇文章主要介紹了
linux c语言每天的0~12:00随机执行操作
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
linux c語言每天的0~12:00隨機執行操作
- 代碼片段
代碼片段
#include <stdio.h> #include <time.h> #include <stdlib.h> #define MAX_RANGE (60*60*12)unsigned int ConvertTimeToTimestamp(int year,int month,int day) {struct tm timestruct;unsigned int timestamp = 0;timestruct.tm_year = year;timestruct.tm_mon = month;timestruct.tm_mday = day;timestruct.tm_hour = 0;timestruct.tm_min = 0;timestruct.tm_sec = 0;timestruct.tm_isdst = -1; timestamp = mktime(×truct);printf("mktime stamp:%d\r\n",timestamp);return timestamp; }int main() {time_t timep;struct tm *p;unsigned int timestamp = 0;unsigned int nextstamp = 0;unsigned char PreDay = 0;unsigned char CurentDay = 0;timestamp = time (&timep);//p=gmtime(&timep);p=localtime(&timep);PreDay = 0;CurentDay = p->tm_mday;printf("%02d-%02d-%02d %02d:%02d:%02d\n",1900+p->tm_year,1+p->tm_mon,p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec);printf("timestamp:%d\r\n",timestamp);while (1){timestamp = time (&timep);//p=gmtime(&timep);p=localtime(&timep);CurentDay = p->tm_mday;if(CurentDay != PreDay){PreDay = CurentDay;//next invoke timenextstamp = ConvertTimeToTimestamp(p->tm_year,p->tm_mon,p->tm_mday);printf("timestamp:%d,basestamp:%d\r\n",timestamp,nextstamp);srand(time(0));nextstamp += (rand()%MAX_RANGE);printf("renew timestamp:%d,nextstamp:%d\r\n",timestamp,nextstamp);if(timestamp > nextstamp){nextstamp = timestamp;}}if(timestamp == nextstamp){printf("invoked .... \r\n");}sleep(1);}return 0; }總結
以上是生活随笔為你收集整理的linux c语言每天的0~12:00随机执行操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 库卡机器人Officelite运行Eth
- 下一篇: 11月13号,我们在杭州有个高规格的大会