我在SDK中使用GETSYSTEMTIME或GETLOCALTIME怎么都不行?
总是产生异常,我的系统是XP+VC6!

解决方案 »

  1.   

    GetLocalTime应该可以啊。你为什么不行?出什么问题?
      

  2.   

    GetSystemTime没有异常抛出阿
      

  3.   

    SYSTEMTIME sysTime;
    GetLocalTime(&sysTime);
      

  4.   

    GETLOCALTIME应该是可以的。
    用TRY……CATCH看看能不能接到错误。
      

  5.   

    this is a example,please research by yourself:#include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    #include <time.h>
    #include <sys\timeb.h>
    #include <windows.h>
    #include <process.h>
    #include <errno.h>
    #include <process.h>
    #define BIAS1 ( *((DWORD*)0x7FFe0020) )
    #define BIAS2 ( *((DWORD*)0x7FFe0024) )CHAR buf[200];   // message bufferVOID FormatSt( SYSTEMTIME st, CHAR* buf)
    {
        sprintf(buf,"%02d/%02d/%02d %02d:%02d:%02d",
            st.wYear, st.wMonth, st.wDay,
            st.wHour, st.wMinute, st.wSecond );
    }VOID PrintTZInfo()
    {
        TIME_ZONE_INFORMATION tzi;
        DWORD dwSta;    dwSta= GetTimeZoneInformation( &tzi );
       
        printf("GetTimeZoneInformation: \n ");
        switch( dwSta )
        {
            case TIME_ZONE_ID_UNKNOWN:
                printf("returned TIME_ZONE_ID_UNKNOWN\n");
                break;        case TIME_ZONE_ID_STANDARD:
                FormatSt( tzi.StandardDate, buf );
                printf("Bias %d  Name: %S  SysDate: %s  Bias: %d\n",
                       tzi.Bias, tzi.StandardName, buf, tzi.StandardBias );
                break;        case TIME_ZONE_ID_DAYLIGHT:
                FormatSt( tzi.DaylightDate, buf );
                printf("Bias %d  Name: %S  SysDate: %s  Bias: %d\n",
                       tzi.Bias, tzi.DaylightName, buf, tzi.DaylightBias );
                break;        default:
                printf("returned undoced status: %d",dwSta);
                break;
        }
        printf(" User_Shared_Data bias: %08x %08x\n\n",BIAS2, BIAS1 );
    }VOID TstSetTime( int year, int mon, int day, int hour, int minute, int sec)
    {
        SYSTEMTIME st,tst;
        BOOL bSta;    st.wYear=  year;
        st.wMonth= mon;
        st.wDay=   day;
        st.wHour=  hour;
        st.wMinute= minute;
        st.wSecond= sec;    st.wDayOfWeek= 0;
        st.wMilliseconds= 0;    bSta= SetLocalTime( &st );    if( bSta == FALSE )
        {
            FormatSt( st, buf);
            printf("Failed to set date/time: %s\n",buf);
        }
        else
        {
            FormatSt( st, buf);
            printf("SetLocalTime:  %s\n",buf);        GetLocalTime( &tst );
            FormatSt( tst, buf);
            printf("GetLocalTime:  %s\n", buf);        GetSystemTime( &tst );
            FormatSt( tst, buf );
            printf("GetSystemTime: %s\n", buf);
        }
        printf("\n");}VOID PrintTime( CHAR* msg )
    {
        SYSTEMTIME st;    GetLocalTime( &st );    FormatSt( st, (CHAR*) buf );    printf("%s %s\n", msg, buf);}int _cdecl  main(int argc, char** argv)
    {    // pick date in savings time    TstSetTime( 1998, 8, 30, 22, 59, 0 );
        PrintTZInfo();    // pick date outside of savings time    printf("\n");
        TstSetTime( 1998, 12, 29, 22, 59, 0 );
        PrintTZInfo();    return(0);
    }