Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
TimeFunctions.cpp
1 
12 #include "stdafx.h"
13 
14 #ifdef _MSC_VER
15  #include <time.h>
16 
17  #define EPOCH_FILE_TIME 116444736000000000
18 #else
19  #include <sys/time.h>
20 #endif // _MSC_VER
21 
22 #include <wx/datetime.h>
23 #include <string>
24 #include "StringFunctions.h"
25 
26 // get current time
27 long long getcurrenttime() {
28  long long t = 0;
29 
30 // get time
31 #ifdef _MSC_VER
32  FILETIME ft;
33  LARGE_INTEGER lv;
34  long long v64;
35 
36  GetSystemTimeAsFileTime( &ft );
37  lv.LowPart = ft.dwLowDateTime;
38  lv.HighPart = ft.dwHighDateTime;
39 
40  v64 = lv.QuadPart - EPOCH_FILE_TIME;
41  t = v64 / 10000;
42 #else
43  struct timeval tv;
44  gettimeofday( &tv, NULL );
45 
46  t = tv.tv_sec * 1000 + tv.tv_usec / 1000;
47 #endif // _MSC_VER
48 
49  return t;
50 }
51 
52 // date -> string
53 std::string datetostring( struct tm* date ) {
54 
55  std::string strDate;
56 
57  if (date != NULL)
58  {
59  wxDateTime wxWidDate(*date);
60  strDate = FMT( "%02d %s %04d %02d:%02d:%02d", wxWidDate.GetDay(), wxDateTime::GetMonthName(wxWidDate.GetMonth(), wxDateTime::Name_Abbr).c_str(), wxWidDate.GetYear(),
61  wxWidDate.GetHour(), wxWidDate.GetMinute(), wxWidDate.GetSecond());
62  }
63  else
64  {
65  strDate = "";
66  }
67 
68  return strDate;
69 }
#define NULL
Definition: CoreMacros.h:18
interfaces of string function
std::string datetostring(struct tm *date)
date -> string
long long getcurrenttime()
gets current time in miliseconds