title: time.h - struct tm and milliseconds
body: <p>I have log data ranging from 1000 to 100000 entries all from different sources. The objective is to sort this data by time (quickly). I was prototyping in C and i'm stuck because it looks like tm doesn't support milliseconds. Am i missing something here ? Any suggestions ? </p>
  
  <p>Idea:</p>
  
  <ol>
  <li><p>Open file. Parse line-by-line and tokenize fields to c struct via strtok</p>
  
  <p>1.1 Convert Date &amp; Time to "struct tm".</p>
  
  <p>1.2 Build linked list </p></li>
  <li>Sort linked list based on time (don't know which sort algorithm i'd use)</li>
  <li>Output </li>
  </ol>
  
  <p>[Example]</p>
  
  <pre class="lang-none prettyprint-override"><code>YYYY-MM-DD,HH:MM:SS:MS , PID, TID , COMPONENT, Message 
  2017-03-29,20:56:27:088, 3436,2568,COMPONENT, Message String blah blah
  2017-03-29,20:56:27:089, 3436,2568,COMPONENT, Message String baaaaa
  2017-03-29,20:56:27:079, 3436,2568,COMPONENT, Message String roarrr
  2017-03-29,20:56:28:061, 3436,2568,COMPONENT, Message String meow
  2017-03-29,20:56:25:044, 3436,2568,COMPONENT, Message String ruff ruff 
  .
  .
  .
  100000 entries 
  </code></pre>
  
  <hr>
  
  <pre><code>const char T[] = "2017-03-29,20:56:27:088"; //Test String
  time_t result = 0;
  int year = 0, month = 0, day = 0;
  int hour = 0, min = 0, sec = 0, ms = 0;
  
  if (sscanf(T, "%4d-%2d-%2d,%2d:%2d:%2d", &amp;year, &amp;month, &amp;day, &amp;hour, &amp;min, &amp;sec) == 6) {
      struct tm tv = {0};
      tv.tm_year = year;
      tv.tm_mon = month;
      tv.tm_mday = day;
      tv.tm_hour = hour;
      tv.tm_min = min;
      tv.tm_sec = sec;
      //Crap, it doesn't look like tm handles milliseconds ????
  
      if ((result = mktime(&amp;tv)) == (time_t)-1) {
          fprintf(stderr, "Conversion Error\n");
      }
      puts(ctime(&amp;result));
  }
  else {
      fprintf(stderr, "Invalid Format\n");
  }
  </code></pre>