#include <stdio.h>
#include <stdlib.h>
#include "time.h"
void Send_Message_To_Data_Server(struct tm *tm, time_t t)
{
struct tm *now; //实时时间
/**打印org处获得的tm(指针),实际指针所指的内容在调用localtime()时被更改了*/
printf("A:%d %d %d %ld\n",tm->tm_hour,tm->tm_min,tm->tm_sec,t);
/**转换org处获得的秒数*/
now = localtime(&t);
printf("B:%d %d %d %ld\n",now->tm_hour,now->tm_min,now->tm_sec,t);
}
void Send_Message_To_Data_Server_With_Ask(struct tm *tm, time_t t)
{
time_t timep;
struct tm *now; //实时时间
int i=0;
for(i=0;i<3;i++)
{
/**C 第2次获取时间**/
time(&timep);
now = localtime(&timep);
printf("C:%d %d %d %ld\n",now->tm_hour,now->tm_min,now->tm_sec,timep);
Send_Message_To_Data_Server(tm,t);
sleep(2);
}
}
int main()
{
time_t timep;
struct tm *now; //实时时间
/**org 第一次获取时间**/
time(&timep);
now = localtime(&timep);
printf("ORG:%d %d %d %ld\n",now->tm_hour,now->tm_min,now->tm_sec,timep);
Send_Message_To_Data_Server_With_Ask(now,timep);
printf("Hello world!\n");
return 0;
}
输出如图