title: ctime() and date/time conversion
body: <p>I know, this particular kind of thing has been answered a number of times, but I think, my question here is more to do with general C++ stuff than <code>ctime()</code> or date/time conversion. I just happened to try it out with this. So, here is the code:    </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ctime&gt;
  
  using std::cout;
  using std::endl;
  using std::string;
  
  void strTime( int iM, int iD, int iY )
  {
      time_t rwTime;
      time( &amp;rwTime );            // current epoch time
  
      // 1st set:: using tmInfo_11
      struct tm *tmInfo_11; 
      tmInfo_11 = localtime( &amp;rwTime );
      tmInfo_11-&gt;tm_mon = iM - 1;
      tmInfo_11-&gt;tm_mday = iD; 
      tmInfo_11-&gt;tm_year = iY - 1900;
      mktime( tmInfo_11 );
      cout &lt;&lt; "tmInfo_11 RESULt: " &lt;&lt; tmInfo_11-&gt;tm_wday &lt;&lt; endl;
  
      // 2nd set:: using tmInfo_22 //
      struct tm tmInfo_22; 
      tmInfo_22 = *localtime( &amp;rwTime );
      tmInfo_22.tm_mon = iM - 1;
      tmInfo_22.tm_mday = iD; 
      tmInfo_22.tm_year = iY - 1900;
      mktime( &amp;tmInfo_22 );
      cout &lt;&lt; "tmInfo_22 RESULt: " &lt;&lt; tmInfo_22.tm_wday &lt;&lt; endl;
  }
  
  int main()
  {
      int iMM=12, iDD=9, iYY=2009;
      strTime( iMM, iDD, iYY );
  }
  </code></pre>
  
  <p>and my question is: What's the difference between these 2 sets of code? Either way, I can achieve the same thing. The notable difference is the first 2-lines from the each set and I have to admit that I didn't understand all of it. So, can anyone kindly explain it to me please? Also, dose one have any advantage(s)/disadvantage(s) over other? Cheers!!<br>
  <hr>
  <em>Just for the sake of completeness</em>, this the code I ended up with, which gives me the desired result. So, basically it's for the future reference: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;ctime&gt;
  
  using std::cout;
  using std::endl;
  using std::string;
  
  tm testTime( int iM, int iD, int iY );
  
  int main()
  {
      char tmBuff[20];
      int iMM=12, iDD=9, iYY=2009;
  
      tm myDate = testTime( iMM, iDD, iYY );
      strftime( tmBuff, sizeof(tmBuff), "%a, %b %d, %Y", &amp;myDate );
      cout &lt;&lt; "TESt PRINt TIMe: " &lt;&lt; tmBuff &lt;&lt; endl;
  }
  
  tm testTime( int iM, int iD, int iY ) 
  {
      time_t rwTime; 
  
      struct tm tmTime;
      tmTime = *localtime( &amp;rwTime );
  
      tmTime.tm_mon = iM - 1;
      tmTime.tm_mday = iD; 
      tmTime.tm_year = iY - 1900;
      mktime( &amp;tmTime );
      return tmTime;
  }
  </code></pre>
  
  <p><strong>NOTE</strong> that it does require the <code>*localtime( &amp;rwTime )</code> to be specified (even though tmTime is getting overwritten afterwards) otherwise the Year(%Y) in the <code>strftime()</code> doesn't work. Thanks to all for helping. Cheers!!</p>