Go to the documentation of this file.00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009 #include "vul_get_timestamp.h"
00010
00011 #include <vcl_compiler.h>
00012
00013 #if defined(VCL_WIN32) && !defined(__CYGWIN__)
00014 #include <direct.h>
00015 #else
00016 #include <unistd.h>
00017 #endif
00018
00019 #include <vcl_sys/time.h>
00020
00021
00022 #include <vcl_ctime.h>
00023 #include <vul/vul_string.h>
00024 #include <vcl_sstream.h>
00025 #include <vcl_iomanip.h>
00026
00027
00028 #if !defined(VCL_WIN32) || defined(__CYGWIN__)
00029
00030 void vul_get_timestamp(int &secs, int &msecs)
00031 {
00032 struct timeval timestamp;
00033 struct timezone* dummy = 0;
00034 gettimeofday(×tamp, dummy);
00035
00036 secs = timestamp.tv_sec;
00037 msecs = timestamp.tv_usec/1000;
00038 }
00039 #elif defined(VCL_WIN32) && defined(VCL_BORLAND)
00040
00041 void vul_get_timestamp(int &secs, int &msecs)
00042 {
00043 struct timeb real;
00044 ftime(&real);
00045
00046 secs = real.time;
00047 msecs = real.millitm;
00048 }
00049 #else
00050
00051 void vul_get_timestamp(int &secs, int &msecs)
00052 {
00053 struct _timeb real;
00054 _ftime(&real);
00055
00056 secs = static_cast<int>(real.time);
00057 msecs = real.millitm;
00058 }
00059 #endif
00060
00061
00062
00063 vcl_string vul_get_time_as_string(vul_time_style style)
00064 {
00065 vcl_string timestr;
00066
00067
00068 vcl_time_t time_secs;
00069 vcl_time(&time_secs);
00070
00071
00072 struct vcl_tm *time;
00073 time = vcl_localtime(&time_secs);
00074
00075 switch (style)
00076 {
00077 case vul_numeric_msf:
00078 {
00079
00080
00081
00082
00083 vcl_ostringstream oss;
00084 oss.fill('0');
00085 oss << vcl_setw(4) << 1900+time->tm_year << ' '
00086 << vcl_setw(2) << 1 + time->tm_mon << ' '
00087 << vcl_setw(2) << time->tm_mday << ' '
00088 << vcl_setw(2) << time->tm_hour << ' '
00089 << vcl_setw(2) << time->tm_min << ' '
00090 << vcl_setw(2) << time->tm_sec;
00091 timestr = oss.str();
00092 }
00093 break;
00094
00095 default:
00096 {
00097
00098
00099 timestr = vcl_asctime(time);
00100 vul_string_right_trim(timestr, "\n");
00101 }
00102 break;
00103 }
00104
00105 return timestr;
00106 }
00107