00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "TimeUtils.hpp"
00021
00022 #include <ctime>
00023 #include <cstring>
00024 #include <cstdio>
00025
00026 long ms_difftime (struct timeval* P_final, struct timeval* P_init)
00027 {
00028 long L_val_sec, L_val_usec;
00029
00030 L_val_sec = P_final->tv_sec - P_init->tv_sec;
00031 L_val_usec = P_final->tv_usec - P_init->tv_usec;
00032 if (L_val_usec < 0) L_val_usec += 1000000, L_val_sec--;
00033 return (L_val_sec*1000 + L_val_usec/1000);
00034
00035 }
00036
00037 void time_tochar (char *P_time, struct timeval* P_tv)
00038 {
00039 struct tm * L_currentDate;
00040
00041
00042 L_currentDate = localtime ((const time_t *)&P_tv->tv_sec);
00043
00044
00045 if (L_currentDate == NULL) {
00046 memset (P_time, 0, TIME_STRING_LENGTH);
00047 } else {
00048 sprintf(P_time,
00049 "%4.4d-%2.2d-%2.2d.%2.2d:%2.2d:%2.2d.%3.3d",
00050 L_currentDate->tm_year + 1900,
00051 L_currentDate->tm_mon + 1,
00052 L_currentDate->tm_mday,
00053 L_currentDate->tm_hour,
00054 L_currentDate->tm_min,
00055 L_currentDate->tm_sec,
00056 (int)((P_tv->tv_usec)/1000));
00057 }
00058 }
00059
00060 void time_tochar_minus (char *P_time, struct timeval* P_tv)
00061 {
00062 struct tm * L_currentDate;
00063
00064
00065 L_currentDate = localtime ((const time_t *)&P_tv->tv_sec);
00066
00067
00068 if (L_currentDate == NULL) {
00069 memset (P_time, 0, TIME_STRING_LENGTH);
00070 } else {
00071 sprintf(P_time,
00072 "%4.4d-%2.2d-%2.2d.%2.2d-%2.2d-%2.2d.%3.3d",
00073 L_currentDate->tm_year + 1900,
00074 L_currentDate->tm_mon + 1,
00075 L_currentDate->tm_mday,
00076 L_currentDate->tm_hour,
00077 L_currentDate->tm_min,
00078 L_currentDate->tm_sec,
00079 (int)((P_tv->tv_usec)/1000));
00080 }
00081 }
00082