time_t now;
time(&now);
// char timestr[16] = {0};
// long2String(now,timestr);
time_t PTime = 0;
// time_t now = 1651075170; // 时间戳,可以用time(&mytime);获取当前时间戳
struct tm* timeP;
char buffer[128]= {0};
/*利用东八区(北京时间,其他国家,美国,英国等,需要相应的进行加或者减X小时), 则真正的换算时间戳为*/
PTime = now + (8 * 60 *60);
timeP = localtime(&PTime); // 转换
// printf("%d/%d/%d %d:%d:%d\n",1900+ timeP->tm_year,1+ timeP->tm_mon,
// timeP->tm_mday, timeP->tm_hour, timeP->tm_min, timeP->tm_sec);
long2Date(timeP,buffer);
FILE *outFile;
outFile = fopen("/assets/wy_temp_hum.dat","at+");
fwrite(buffer, sizeof(char), strlen(buffer), outFile);
fwrite("\n", 1, 2, outFile);//换行
fclose(outFile);
//long转字符串
char* long2String( long s1 , char *str);//函数声明
char* long2String(long s1 , char *str)
{
sprintf(str, " %4d",s1);
return str;
}
//tm 转日期字符串
char* long2Date( struct tm* timeP , char *str);//函数声明
char* long2Date(struct tm* timeP , char *str)
{
sprintf(str,"%d/%d/%d %d:%d:%d ",1900+ timeP->tm_year,1+ timeP->tm_mon,
timeP->tm_mday, timeP->tm_hour, timeP->tm_min, timeP->tm_sec);
return str;
}