Gang YIN
Gang YIN

Reputation: 2567

How to get a local time instead of UTC time in ACE?

I've been using the ACE_OS::gettimeofday() in a program to get the current time. From what I know, ACE always use UTC internally. However, sometimes I do need to convert the UTC time to a local time based on the system's timezone.

Is it possible to do this conversion without using any platform-specific technique? Any suggestion would be appreciated.

Upvotes: 1

Views: 3804

Answers (2)

Gang YIN
Gang YIN

Reputation: 2567

@ArunMu

By some googling, which follows your answer of course, I found the following solution, thanks!

time_t temptime = ACE_OS::gettimeofday().sec();

tm* timeinfo = ACE_OS::localtime(&temptime); // local time

tm* timeinfo = ACE_OS::gmtime(&temptime);    // UTC/GMT time

Upvotes: 2

Arunmu
Arunmu

Reputation: 6901


    #include <time.h>
    #include < iostream >
    int main(){
       time_t tempTime;
       time(&tempTime);
       struct timeval tv;
       gettimeofday(&tv, NULL);
       long int m_eventTime = temptime - timezone ;

    return 0;
   }

I use the above in Unix/Linux to convert to local time. m_eventTime variable hold the epoch as per your timezone

Upvotes: 2

Related Questions