示例#1
0
/**
 * @brief 获得当前时间
 */
int TS_GetTimeNow(ts_time_t* tw) {
	uint32 secs;
	JulianType julian;
	
	if( NULL == tw )
		return -1;
	
	secs = GETTIMESECONDS();
	GETJULIANDATE(secs,&julian);
	
	tw->year = julian.wYear;
	tw->month = (uint8)julian.wMonth;
	tw->day = (uint8)julian.wDay;
	tw->hour = (uint8)julian.wHour;
	tw->minute = (uint8)julian.wMinute;
	tw->second = (uint8)julian.wSecond;
	tw->millisecond = 0;
	
	return 0;
}
示例#2
0
文件: File.cpp 项目: bonly/Template
int log(const char *fmt, ...)
{
    if (!Log.good())
        Log.open("MyLog.txt");

    if (!Log.good())
        return -1;

    ZeroMemory(gpcDebug, sizeof(gpcDebug));

    JulianType ttt;
    GETJULIANDATE(0, &ttt);
    
    //SPRINTF(gpcDebug, "%d:%d:%d:%d %s:%d", ttt.wHour, ttt.wMinute, ttt.wSecond,
    //            currentTimeMillis(),__FILE__, __LINE__);
    
    SPRINTF(gpcDebug, "[%s:%s]", __DATE__, __TIME__);
    char* ptc = &gpcDebug[STRLEN(gpcDebug)];
    va_list p;
    va_start(p, fmt);

    for (const char *s = fmt; *s; ++s)
    {
        if (*s != '%')
        {
            *(ptc++) = *s;
        }
        else
        {
            switch (*(++s))
            {
                case '%':
                {
                    *(ptc++) = '%';
                }
                    break;
                case 's':
                {
                    const char* pc = va_arg(p, const char*);
                    while (*pc)
                    {
                        *(ptc++) = *(pc++);
                    }
                }
                    break;
                case 'c':
                {
                    *(ptc++) = va_arg(p, char);
                }
                    break;
                case 'd':
                {
                    int nNum = va_arg(p, int);

                    char pc[32] = { 0 };

                    if (nNum < 0)
                    {
                        *(ptc++) = '-';
                        nNum = -nNum;
                    }
                    else if (nNum == 0)
                    {
                        *(ptc++) = '0';
                    }

                    int nIndex = 32;
                    while (nNum > 0)
                    {
                        nIndex--;
                        pc[nIndex] = (int) (nNum % 10) + '0';
                        nNum /= 10;
                    }

                    for (; nIndex < 32;)
                    {
                        *(ptc++) = pc[nIndex++];
                    }
                }
                    break;
                case 'u':
                {
                    unsigned int nNum = va_arg(p, unsigned int);

                    char pc[32] = { 0 };

                    if (nNum == 0)
                    {
                        *(ptc++) = '0';
                    }

                    int nIndex = 32;
                    while (nNum > 0)
                    {
                        nIndex--;
                        pc[nIndex] = (int) (nNum % 10) + '0';
                        nNum /= 10;
                    }

                    for (; nIndex < 32;)
                    {
                        *(ptc++) = pc[nIndex++];
                    }
                }
                    break;
                case 'p':
                {
                    *(ptc++) = '0';
                    *(ptc++) = 'x';

                    unsigned int unNum = va_arg(p, unsigned int);

                    char pc[32] = { 0 };

                    if (unNum == 0)
                    {
                        *(ptc++) = '0';
                    }

                    int nIndex = 32;
                    while (unNum > 0)
                    {
                        nIndex--;
                        int n = (int) (unNum % 16);
                        if (n < 10)
                            pc[nIndex] = n + '0';
                        else
                            pc[nIndex] = n - 10 + 'a';
                        unNum >>= 4;
                    }

                    for (; nIndex < 32;)
                    {
                        *(ptc++) = pc[nIndex++];
                    }
                }
                    break;
                default:
                    break;
            }
        }
    }
    va_end(p);
    *ptc = 0;

    return Log.write((void*) gpcDebug, STRLEN(gpcDebug));
}