diff options
author | Benoit Foucher <benoit@zeroc.com> | 2003-03-06 20:14:35 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2003-03-06 20:14:35 +0000 |
commit | 40a2e5677daadbf4fafd6111de6040163ee42869 (patch) | |
tree | acef4a4aa9896b3f04186274c44e6d6c454fb8ea /cpp/src/IceUtil/Time.cpp | |
parent | Fixed bug caused by a redundant check for encapsulation version that left (diff) | |
download | ice-40a2e5677daadbf4fafd6111de6040163ee42869.tar.bz2 ice-40a2e5677daadbf4fafd6111de6040163ee42869.tar.xz ice-40a2e5677daadbf4fafd6111de6040163ee42869.zip |
Added IceUtil::Time::toString() and support for timestamps in the default
logger.
Diffstat (limited to 'cpp/src/IceUtil/Time.cpp')
-rw-r--r-- | cpp/src/IceUtil/Time.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cpp/src/IceUtil/Time.cpp b/cpp/src/IceUtil/Time.cpp index 678b9a8f8f0..ee3cecd88cc 100644 --- a/cpp/src/IceUtil/Time.cpp +++ b/cpp/src/IceUtil/Time.cpp @@ -16,6 +16,7 @@ #ifdef _WIN32 # include <sys/timeb.h> +# include <time.h> #else # include <sys/time.h> #endif @@ -140,6 +141,31 @@ IceUtil::Time::operator double() const return _usec / 1000000.0L; } +std::string +IceUtil::Time::toString() const +{ + time_t time = static_cast<long>(_usec / 1000000); + + struct tm* t; +#ifdef _WIN32 + t = localtime(&time); +#else + struct tm tr; + localtime_r(&time, &tr); + t = &tr; +#endif + + char buf[32]; + strftime(buf, sizeof(buf), "%x %H:%M:%S", t); + + std::ostringstream os; + os << buf << ":"; + os.fill('0'); + os.width(3); + os << static_cast<long>(_usec % 1000000 / 1000); + return os.str(); +} + Time::Time(Int64 usec) : _usec(usec) { |