更新时间:2022-12-23 20:44:15
我想对此问题提交另一个答案,即AFAICS也处理IDL.
I would like to submit yet another answer to this question, one that AFAICS also deals with the IDL.
此解决方案取决于timegm
和mktime
.在Windows上,CRT中的timegm
作为_mkgmtime
可用,换句话说,定义了条件宏.
This solution depends on timegm
and mktime
. On Windows timegm
is available as _mkgmtime
from the CRT, in other words define a conditional macro.
#if _WIN32
# define timegm _mkgmtime
#endif
int local_utc_offset_minutes ( ) {
time_t t = time ( NULL );
struct tm * locg = localtime ( &t );
struct tm locl;
memcpy ( &locl, locg, sizeof ( struct tm ) );
return (int)( timegm ( locg ) - mktime ( &locl ) ) / 60;
}