37 lines
901 B
C++
37 lines
901 B
C++
|
#include "HGTime.h"
|
||
|
#include "HGInc.h"
|
||
|
|
||
|
HGResult HGAPI HGBase_GetLocalTime(HGTimeInfo* timeInfo)
|
||
|
{
|
||
|
if (NULL == timeInfo)
|
||
|
{
|
||
|
return HGBASE_ERR_INVALIDARG;
|
||
|
}
|
||
|
|
||
|
#if defined(HG_CMP_MSC)
|
||
|
SYSTEMTIME st;
|
||
|
GetLocalTime(&st);
|
||
|
timeInfo->year = st.wYear;
|
||
|
timeInfo->month = st.wMonth;
|
||
|
timeInfo->day = st.wDay;
|
||
|
timeInfo->dayOfWeek = st.wDayOfWeek;
|
||
|
timeInfo->hour = st.wHour;
|
||
|
timeInfo->minute = st.wMinute;
|
||
|
timeInfo->second = st.wSecond;
|
||
|
timeInfo->milliseconds = st.wMilliseconds;
|
||
|
#else
|
||
|
struct timeval time;
|
||
|
gettimeofday(&time, NULL);
|
||
|
struct tm* p = localtime(&time.tv_sec);
|
||
|
assert(NULL != p);
|
||
|
timeInfo->year = p->tm_year + 1900;
|
||
|
timeInfo->month = 1 + p->tm_mon;
|
||
|
timeInfo->day = p->tm_mday;
|
||
|
timeInfo->dayOfWeek = p->tm_wday;
|
||
|
timeInfo->hour = p->tm_hour;
|
||
|
timeInfo->minute = p->tm_min;
|
||
|
timeInfo->second = p->tm_sec;
|
||
|
timeInfo->milliseconds = time.tv_usec / 1000;
|
||
|
#endif
|
||
|
return HGBASE_ERR_OK;
|
||
|
}
|