title: How to print timestamp of a packet read from pcap file?
body: <p>I am trying to read the packets from a pcap file using a c program and print the time-stamp of each packet.</p>
  
  <p>I am using the below line of code to print the timestamp:</p>
  
  <pre><code>printf("%s,",ctime((const time_t*)&amp;header-&gt;ts.tv_sec));
  </code></pre>
  
  <p>And my output is as below:</p>
  
  <pre><code>Mon Jan 14 09:48:18 2013
  </code></pre>
  
  <p>How do I get it as YYYY-MM-DD HH:MM:SS like the one shown below?</p>
  
  <pre><code>2016-02-16 13:14:33.224487
  </code></pre>
  
  <p>I am new to c programming and have no clue what i am doing. Please help.
  Thanks!</p>