title: Last modified time of file in C
body: <p>I am trying to get the last modified time of a file in C/Linux, but the time always comes out wrong.</p>
  
  <pre><code>struct stat attrib;
  stat("/etc/example/file.txt", &amp;attrib);
  char time[50];
  strftime(time, 50, '%Y-%m-%d %H:%M:%S", localtime(&amp;attrib.st_mtime));
  </code></pre>
  
  <p>Printing time gives me "2024-05-01 15:35:21". The year and day are obviously wrong. I have tried different options such as gmtime instead of localtime, but it does not produce the correct output. using "ls -l" shows the correct Month, Day, and Year...So I'm not sure what I am doing wrong.</p>