1

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.

Gang YIN
  • 2,509
  • 2
  • 21
  • 25

2 Answers2

2

    #include &lttime.h&gt
    #include &lt iostream &gt
    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

Arunmu
  • 6,837
  • 1
  • 24
  • 46
2

@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
Gang YIN
  • 2,509
  • 2
  • 21
  • 25