ACE_Time_Value ------> ACE_Date_Time explicit ACE_Date_Time (const ACE_Time_Value& timevalue);
ACE_Time_Value ------> long ACE_OS::gettimeofday().get_msec()
long ------> ACE_Time_Value void ACE_Time_Value ::set_msec (const ACE_UINT64 &ms);
#include "ace/Log_Msg.h"
#include "ace/OS.h"
#include "ace/Date_Time.h"
#include "ace/Time_Value.h"
#include
#include
using namespace std;
//print ace_date_time
void print_ace_date(const ACE_Date_Time& date)
{
ACE_DEBUG((LM_DEBUG,"%d-%d-%d %d:%d:%d:%d\n",
date.year(),
date.month(),
date.day(),
date.hour(),
date.minute(),
date.second(),
date.microsec()));
}
void print_ace_time(const string& name,const ACE_Time_Value& t)
{
cout< half_second)
{
cout<<"one_second > half_second"< zero_time)
{
cout<<"half_second > zero_time"< t2)
{
cout< "<
官网介绍:http://www.dre.vanderbilt.edu/Doxygen/6.0.1/html/libace-doc/a00559.html
ACE_Time_Value使用注意事项 http://blog.csdn.net/stephenxu111/article/details/6457659
ACE_Time_Value使用注意事项(续) http://blog.csdn.net/stephenxu111/article/details/9053945
很好的说明了具体用法
//=============================================================================
/**
* @file Time_Value_Test.cpp
*
* $Id: Time_Value_Test.cpp 95763 2012-05-16 06:43:51Z johnnyw $
*
* This is a simple test of ACE_Time_Value. No command line arguments
* are needed to run the test.
*
* @author Prashant Jain and David Levine
*/
//=============================================================================
// Note, for this test the config.h file *must* come first!
#include "ace/config-all.h"
#include "test_config.h"
#include "ace/ACE.h"
#include "ace/Time_Value.h"
#include "ace/Numeric_Limits.h"
#ifdef ACE_HAS_CPP98_IOSTREAMS
#include
#endif
int
run_main (int, ACE_TCHAR *[])
{
int ret = 0;
ACE_START_TEST (ACE_TEXT ("Time_Value_Test"));
ACE_Time_Value tv1;//0秒
ACE_Time_Value tv2 (2);//2秒
ACE_Time_Value tv3 (100U);//100秒
ACE_Time_Value tv4 (1, 1000000);//2秒
ACE_Time_Value tv5 (2UL);//2秒
ACE_Time_Value tv6 (1, -1000000);//0秒
ACE_Time_Value tv7 (static_cast (2.0));//2秒
// Beware! 2.5 gets truncated to 2!
// NOTE: this is intended to show what happens with
// ACE_Time_Value (2.5). Some compilers, such as g++ 2.7.2.3,
// actually warn about it without the case.
ACE_Time_Value tv8 (static_cast (2.5));//2秒
ACE_Time_Value first;
ACE_Time_Value last(ACE_Time_Value::max_time);
first = last;
ACE_TEST_ASSERT (first == last);
// Test assignment operator, tv9 and tv6 must be the same after this
ACE_Time_Value tv9;
tv9 = tv6;
ACE_TEST_ASSERT (tv1 == ACE_Time_Value (0));
ACE_TEST_ASSERT (tv2 < tv3);
ACE_TEST_ASSERT (tv2 <= tv2);
ACE_TEST_ASSERT (tv2 >= tv4);
ACE_TEST_ASSERT (tv5 >= tv6);
ACE_TEST_ASSERT (tv2 == ACE_Time_Value (1, 1000000));//tv2 (2);//2秒 == ACE_Time_Value (1, 1000000))
ACE_TEST_ASSERT (tv5 == tv4);
ACE_TEST_ASSERT (tv2 == tv4);
ACE_TEST_ASSERT (tv1 != tv2);
ACE_TEST_ASSERT (tv6 == tv1);
ACE_TEST_ASSERT (tv5 == tv7);
ACE_TEST_ASSERT (tv7 == tv8); // That's right! See above . . .
ACE_TEST_ASSERT (tv9 == tv6);
ACE_Time_Value tv10 (1);
ACE_TEST_ASSERT (tv10.sec() == 1);
// test multiplication by double
// test simple multiplication
tv1.set (1, 1);
tv2.set (2, 2);
tv1 *= 2.0;
ACE_TEST_ASSERT (tv1 == tv2);
tv1.set (1, 1);
tv2.set (static_cast (-2), static_cast (-2));
tv1 *= -2.0;
ACE_TEST_ASSERT (tv1 == tv2);
// test usec shift
tv1.set (1, 999999);
tv2.set (19, 999990);
tv1 *= 10.0;
ACE_TEST_ASSERT ( tv1 == tv2);
tv1.set (1, 999999);
tv2.set (static_cast (-19), -999990);
tv1 *= -10.0;
ACE_TEST_ASSERT (tv1 == tv2);
// Test correct msec() convert; also checks for compile error reported in
// Bugzilla 3336.
ACE_Time_Value msec_test (42, 555000);
ACE_UINT64 ms = 0;
msec_test.msec (ms);
if (ms != 42555)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("msec test failed: %Q should be 42555\n"),
ms));
ms = 0;
ms = msec_test.get_msec ();
if (ms != 42555)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("get_msec test failed: %Q should be 42555\n"),
ms));
ACE_Time_Value const msec_test2 (42, 555000);
ms = 0;
msec_test2.msec (ms);
if (ms != 42555)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("msec const test failed: %Q should be 42555\n"),
ms));
// Test setting from ACE_UINT64
ms = 42555;
ACE_Time_Value msec_test3;
msec_test3.set_msec (ms);
if (msec_test3.sec () != 42)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("set_msec test failed: %d secs should be 42\n"),
msec_test3.sec ()));
if (msec_test3.usec () != 555000)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("set_msec test failed: %d usecs should be 555000\n"),
msec_test3.usec ()));
#ifdef ACE_HAS_CPP98_IOSTREAMS
std::ostringstream ost;
ost << ACE_Time_Value(1);
ACE_TEST_ASSERT( ost.str() == "1" );
ost.str("");
ost << ACE_Time_Value(1,1);
ACE_TEST_ASSERT( ost.str() == "1.000001" );
ost.str("");
ost << ACE_Time_Value(static_cast(-1),-1);
ACE_TEST_ASSERT( ost.str() == "-1.000001" );
ost.str("");
ost << ACE_Time_Value(0,1);
ACE_TEST_ASSERT( ost.str() == "0.000001" );
ost.str("");
ost << ACE_Time_Value(0,-1);
ACE_TEST_ASSERT( ost.str() == "-0.000001" );
ost.str("");
ost << ACE_Time_Value();
ACE_TEST_ASSERT( ost.str() == "0" );
#endif
ACE_END_TEST;
return ret;
}
ACE_Time_Value ------> ACE_Date_Time explicit ACE_Date_Time (const ACE_Time_Value& timevalue);
ACE_Time_Value ------> long ACE_OS::gettimeofday().get_msec()
long ------> ACE_Time_Value void ACE_Time_Value ::set_msec (const ACE_UINT64 &ms);