title: windows timestamp (C++)
body: <p>I creating windows timestamp() function and I got wrong numbers checking by PHP microtime() function:</p>
  
  <ul>
  <li><strong>C++</strong> = 1409802313</li>
  <li><strong>PHP</strong> = 1410655505</li>
  </ul>
  
  <p>In this fallowing C++ writed code:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;iostream&gt; // &lt;--- Console I/O
  #include &lt;cstdlib&gt; // &lt;--- Command Line
  #include &lt;sstream&gt;
  
  using namespace std;
  
  void print(string value){cout &lt;&lt; value;}
  
  string parseStr(int value)
  {
  ostringstream stream;
  stream&lt;&lt;value&lt;&lt;flush;
  
  return stream.str();
  }
  
  
  // ============================================================
  //                         TIMESTAMP
  // ============================================================
  string timestamp()
  {
  SYSTEMTIME system_time;
  GetLocalTime(&amp;system_time);
  
  int year = system_time.wYear;
  int month = system_time.wMonth;
  int day = system_time.wDay;
  int hour = system_time.wHour;
  int minute = system_time.wMinute;
  int second = system_time.wSecond;
  int milliseconds = system_time.wMilliseconds;
  
  int day_of_year = 0;
   if (month &gt; 1){day_of_year += 31;} // Sausis
   if (month &gt; 2){day_of_year += 28;} // Vasaris
   if (month &gt; 3){day_of_year += 31;} // Kovas
   if (month &gt; 4){day_of_year += 30;} // Balandis
   if (month &gt; 5){day_of_year += 31;} // Geguze
   if (month &gt; 6){day_of_year += 30;} // Birzelis
   if (month &gt; 7){day_of_year += 31;} // Liepa
   if (month &gt; 8){day_of_year += 31;} // Rugpjutis
   if (month &gt; 9){day_of_year += 30;} // Rugsejis
   if (month &gt; 10){day_of_year += 31;} // Spalis
   if (month &gt; 11){day_of_year += 30;} // Lapkritis
   if (month &gt; 12){day_of_year += 31;} // Gruodis
  day_of_year += day;
  
  int time = 0;
  time += (year - 1970) * 31536000;
  time += day_of_year * 86400;
  time += hour * 3600;
  time += minute * 60;
  time += second;
  
  string time_string;
  time_string = parseStr(time);
  
  return time_string;
  }
  // ============================================================
  
  int main()
  {
   while(true)
   {
   system("cls");
  
   string time = timestamp();
   print(time);
  
   Sleep(100);
   }
  
  return 0;
  }
  </code></pre>
  
  <p>Does i calculating something wrong or something wrong with integer types? :(</p>