NO IMAGE
ACE日誌輸出時用%D輸出時間:
ACE_DEBUG ((LM_INFO, ACE_TEXT (“%DHi Mom/n”)));
結果如:
Thu Mar 13 2008 17:38:01.453000Hi Mom
 
格式不符合中文習慣,並且太長。我把原始碼改了一下,這樣輸出時間時符合中國習慣(比如:08-05-12 09:37:20.123),並且節省輸出長度(Windows下只能輸出到毫秒,所以秒後面只要3位小數即可),改完重新編譯ACE庫即可。
 
 
// ACE.cpp,v 4.357 2003/11/05 23:30:46 shuston Exp
 
#include “ace/ACE.h”
 
#if defined (ACE_LACKS_INLINE_FUNCTIONS)
#include “ace/ACE.i”
#endif /* ACE_LACKS_INLINE_FUNCTIONS */
 
… …
 
// Returns the current timestamp in the form
// “hour:minute:second:microsecond.” The month, day, and year are
// also stored in the beginning of the date_and_time array.
 
ACE_TCHAR *
ACE::timestamp (ACE_TCHARdate_and_time[],
                intdate_and_timelen,
                intreturn_pointer_to_first_digit)
{
 //ACE_TRACE (“ACE::timestamp”);
 
 if (date_and_timelen < 35)
    {
      errno = EINVAL;
      return 0;
    }
 
#if defined (WIN32)
   // Emulate Unix. Win32 does NOT support all the UNIX versions
   // below, so DO we need this ifdef.
 static const ACE_TCHAR *day_of_week_name[] =
 {
    ACE_LIB_TEXT (“Sun”),
    ACE_LIB_TEXT (“Mon”),
    ACE_LIB_TEXT (“Tue”),
    ACE_LIB_TEXT (“Wed”),
    ACE_LIB_TEXT (“Thu”),
    ACE_LIB_TEXT (“Fri”),
    ACE_LIB_TEXT (“Sat”)
 };
 
 static const ACE_TCHAR *month_name[] =
 {
    ACE_LIB_TEXT (“Jan”),
    ACE_LIB_TEXT (“Feb”),
    ACE_LIB_TEXT (“Mar”),
    ACE_LIB_TEXT (“Apr”),
    ACE_LIB_TEXT (“May”),
    ACE_LIB_TEXT (“Jun”),
    ACE_LIB_TEXT (“Jul”),
    ACE_LIB_TEXT (“Aug”),
    ACE_LIB_TEXT (“Sep”),
    ACE_LIB_TEXT (“Oct”),
    ACE_LIB_TEXT (“Nov”),
    ACE_LIB_TEXT (“Dec”)
 };
 
 SYSTEMTIME local;
 ::GetLocalTime (&local);
 
 /*更改以下兩句,輸出08-05-12 09:37:20.123的格式
 ACE_OS::sprintf (date_and_time,
                   ACE_LIB_TEXT (“%3s %3s %2d %04d %02d:%02d:%02d.%06d”),
                   day_of_week_name[local.wDayOfWeek],
                   month_name[local.wMonth – 1],
                   (int) local.wDay,
                   (int) local.wYear,
                   (int) local.wHour,
                   (int) local.wMinute,
                   (int) local.wSecond,
                   (int) (local.wMilliseconds * 1000));
 return &date_and_time[15 (return_pointer_to_first_digit != 0)*/
 ACE_OS::sprintf (date_and_time,
      ACE_LIB_TEXT (“%02d-%02d-%02d %02d:%02d:%02d.%03d”),
      (int) local.wYear – 2000,
      (int) local.wMonth,
      (int) local.wDay,
      (int) local.wHour,
      (int) local.wMinute,
      (int) local.wSecond,
      (int) local.wMilliseconds);
 return &date_and_time[9];
#else  /* UNIX */
 ACE_TCHARtimebuf[26]; // This magic number is based on the ctime(3c) man page.
 ACE_Time_Valuecur_time = ACE_OS::gettimeofday ();
 time_tsecs = cur_time.sec ();
 
 ACE_OS::ctime_r (&secs,
                   timebuf,
                   sizeof timebuf);
 // date_and_timelen > sizeof timebuf!
 ACE_OS::strsncpy (date_and_time,
                    timebuf,
                    date_and_timelen);
 charyeartmp[5];
 ACE_OS::strsncpy (yeartmp,
                    &date_and_time[20],
                    5);
 chartimetmp[9];
 ACE_OS::strsncpy (timetmp,
                    &date_and_time[11],
                    9);
 ACE_OS::sprintf (&date_and_time[11],
                   “%s %s.%06ld”,
                   yeartmp,
                   timetmp,
                   cur_time.usec ());
 date_and_time[33] = ‘/0’;
 return &date_and_time[15 (return_pointer_to_first_digit != 0)];
#endif /* WIN32 */
}