UTC时间记录在夏令时开始前的1点到1点59分重复两次 [英] UTC time record repeating 1:00 to 1:59 am twice, 5 hours before start of daylight saving
问题描述
UTC time record 5 hours before start of Spring Day Light Saving, displays 1:00 to 1:59 UTC time duration am twice. First, from 8:00 pm to 8:59 pm and then again from 9:00 pm to 9:59 pm. UTC time becomes normal 3:00 am again at local 10 pm time.
when local time goes to 8:59 pm to 9:00 pm on 11 March '17, UTC time goes back from 1:59 am to 1:00 am and since then continue to record time upto 1:59 am. And when local time goes to 9:59 pm to 10:00 pm same day, UTC time records goes to 1:59 am to 3:00 am. It all happening before start of Day light saving (5 hours before in UTC-5 time zone).
Summary:
local time duration ----------------- UTC time duration
(11th March '17) --------------------- (12th March '17)
8:00pm to 8:59 pm -------------- 1:00 am to 1:59 am
9:00pm to 9:59 pm -------------- 1:00 am to 1:59 am
10:00 pm onwards --------------- 3:00 am onwards
什么我试过了:
What I have tried:
double TimeCalculationClass :: GetUTCTime()
{
struct tm* starTime;
struct tm stmTime;
time_t localTimestamp = (long)m_dTime;
double dTime;
SYSTEMTIME sysTime, sysUTcST;
FILETIME locFileTime, utcFileTime;
dTime = m_dTime;
/* Convert to a SYSTEMTIME */
sysTime.wSecond = (unsigned short)starTime->tm_sec;
sysTime.wMinute = (unsigned short)starTime->tm_min;
sysTime.wHour = (unsigned short)starTime->tm_hour;
sysTime.wDay = (unsigned short)starTime->tm_mday;
sysTime.wMonth = (unsigned short)(starTime->tm_mon + 1);
sysTime.wYear = (unsigned short)(starTime->tm_year + 1900);
sysTime.wMilliseconds = 0;
/* convert to a local FileTime */
SystemTimeToFileTime(&sysTime, &locFileTime);
/* convert local filetime to a file time based on the Coordinated
Universal Time (UTC). */
LocalFileTimeToFileTime(&locFileTime, &utcFileTime);
/* convert utc filetime to utc system time */
FileTimeToSystemTime(&utcFileTime, &sysUTcST);
/* convert system time to struct tm */
stmTime.tm_sec = sysUTcST.wSecond;
stmTime.tm_min = sysUTcST.wMinute;
stmTime.tm_hour = sysUTcST.wHour;
stmTime.tm_mday = sysUTcST.wDay;
stmTime.tm_mon = sysUTcST.wMonth - 1;
stmTime.tm_year = sysUTcST.wYear - 1900;
stmTime.tm_wday = sysUTcST.wDayOfWeek;
stmTime.tm_yday = 0;
stmTime.tm_isdst = -1;
dTime = (double)mktime(&stmTime);
//if (stTime.wMilliseconds != 0)
dTime = dTime + ((double)sysTime.wMilliseconds / 1000);
return dTime;
}
推荐答案
请参阅 SystemTimeToFileTime函数(Windows) [ ^ ]文档:
See the SystemTimeToFileTime function (Windows)[^] documentation:
将系统时间转换为文件时间格式。系统时间基于协调世界时(UTC)。
Converts a system time to file time format. System time is based on Coordinated Universal Time (UTC).
和 SYSTEMTIME结构(Windows) [ ^ ]:
and SYSTEMTIME structure (Windows)[^]:
时间是协调世界时(UTC)或本地时间,具体取决于被调用的函数。
The time is either in coordinated universal time (UTC) or local time, depending on the function that is being called.
您的代码创建本地 SYSTEMTIME
并将其传递给 SystemTimeToFileTime
,这需要UTC时间。您必须致电 TzSpecificLocalTimeToSystemTime函数(Windows) [ ^ ]首先。
处理时间的一般规则:
始终以UTC格式存储它们并执行所有计算(时间跨度) / duration)使用UTC时间。仅将本地时间用于用户交互(输入/输出)。
Your code creates a local SYSTEMTIME
and passes that to SystemTimeToFileTime
which requires an UTC time. You have to call TzSpecificLocalTimeToSystemTime function (Windows)[^] first.
The general rule for handling times:
Always store them in UTC and perform all calculations (time span / duration) using UTC times. Use local time only for user interaction (input / output).
这篇关于UTC时间记录在夏令时开始前的1点到1点59分重复两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!