Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Konami_Plugin' does not have a method 'header' in /www/wwwroot/www.lijian.net/var/Typecho/Plugin.php on line 446

Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'LaAnalysis_Plugin' not found in /www/wwwroot/www.lijian.net/var/Typecho/Plugin.php on line 446

2023年8月

碰到一个奇怪的问题,通过localtime生成本地日期时间打日志,结果日志会出现非北京时间,好奇去查了一个,结果发现此函数是非线程安全函数,原来代码如下:

int32_t utc2datetime(uint32_t utctime, SVC_TIME* out_pTime)
{
	time_t rawtime;
	struct tm * p;
	rawtime = utctime;
	p = localtime(&rawtime);
	out_pTime->unYear = (uint32_t)(1900 + p->tm_year);
	out_pTime->unMonth = (uint16_t)(1 + p->tm_mon);
	out_pTime->unDay = (uint16_t)p->tm_mday;
	out_pTime->unHour = (uint16_t)p->tm_hour;
	out_pTime->unMinute = (uint16_t)p->tm_min;
	out_pTime->unSecond = (uint16_t)p->tm_sec;
	out_pTime->unWeek = (uint16_t)p->tm_wday;
	return 0;
}

localtime,用来获取系统时间,原型在time.h头文件中,定义如下:

struct tm *localtime(const time_t *timep);

- 阅读剩余部分 -