A method in the C language that converts a timestamp to a time string

  • 2020-05-17 05:56:19
  • OfStack

One of the fields in PE is a timestamp for the creation of the file, and I want to convert it to a string, just to make it more intuitive.


 TCHAR buffer[50] = {0};
 struct tm Tm = {0};
 time_t time = (time_t)NtHeader->FileHeader.TimeDateStamp;// The time stamp  
gmtime_s(&Tm, &time);
printf(buffer, TEXT("%d years %d month %d day  %d:%d:%d"), Tm.tm_year+1900, Tm.tm_mon+1, Tm.tm_mday, Tm.tm_hour+8, Tm.tm_min, Tm.tm_sec);
 // Note: this function calculates the year from 1900 Years from how many years, so to +1900 , the month calculated 0 According to the first 1 I'm going to do it this way, so I'm going to +1 , the calculated time zone is not in China, the difference 8 Hours, so +8.

Related articles: