[英]C++, Convert OADate to struct tm
Excel dates are stored as double in a convention that seems to be called OADate
, is there a built-in function to convert the OADate
to a struct tm
. Excel日期按照似乎称为
OADate
的约定以双OADate
,是否有内置函数将OADate
转换为struct tm
。
For example, in Excel, the 9/May/2014
is 41768
. 例如,在Excel中,
9/May/2014
为41768
。 I need in C++ to find a way to convert 41768
in a struct tm
initialised to the correct date. 我需要在C ++中找到一种方法,以将初始化的
struct tm
41768
转换为正确的日期。
Are there built-in functions to do this ? 有内置的功能可以做到这一点吗? I could use
VariantTimeToSystemTime()
but it converts it to a LPSYSTEMTIME
which needs then to be converted into a struct tm
. 我可以使用
VariantTimeToSystemTime()
但是它将其转换为LPSYSTEMTIME
,然后需要将其转换为struct tm
。 I was looking for something that would do both at the same time. 我一直在寻找可以同时实现两者的功能。 It is not very hard to do but I would rather use built-in functions than writing my own.
这并不是很难,但是我宁愿使用内置函数而不是编写自己的函数。
In the case someone needs to do it, this is enough to make it work: 如果有人需要这样做,这足以使它起作用:
double oaDate = 41678.;
char buffer[256];
struct tm timeinfo;
_SYSTEMTIME lpSystemTime;
VariantTimeToSystemTime(oaDate, &lpSystemTime);
timeinfo.tm_mday = lpSystemTime.wDay;
timeinfo.tm_mon = lpSystemTime.wMonth - 1; // Be careful of different conventions
timeinfo.tm_year = lpSystemTime.wYear - 1900;
timeinfo.tm_hour = lpSystemTime.wHour;
timeinfo.tm_min = lpSystemTime.wMinute;
timeinfo.tm_sec = lpSystemTime.wSecond;
timeinfo.tm_isdst = 0;
mktime(&timeinfo);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.