Embed compile time in executable


/ Published in: C#
Save to your folder(s)

Datestamp of compile time


Copy this code and paste it in your HTML
  1. private DateTime RetrieveLinkerTimestamp()
  2. {
  3. string filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
  4. const int c_PeHeaderOffset = 60;
  5. const int c_LinkerTimestampOffset = 8;
  6. byte[] b = new byte[2048];
  7. System.IO.Stream s = null;
  8.  
  9. try
  10. {
  11. s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
  12. s.Read(b, 0, 2048);
  13. }
  14. finally
  15. {
  16. if (s != null)
  17. {
  18. s.Close();
  19. }
  20. }
  21.  
  22. int i = System.BitConverter.ToInt32(b, c_PeHeaderOffset);
  23. int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
  24. DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);
  25. dt = dt.AddSeconds(secondsSince1970);
  26. dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
  27. return dt;
  28. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.