Proper c# timestamp to String


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



Copy this code and paste it in your HTML
  1. double timestamp = 1113211532;
  2.  
  3. // First make a System.DateTime equivalent to the UNIX Epoch.
  4.  
  5. System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
  6.  
  7. // Add the number of seconds in UNIX timestamp to be converted.
  8.  
  9. dateTime = dateTime.AddSeconds(timestamp);
  10.  
  11. // The dateTime now contains the right date/time so to format the string,
  12.  
  13. // use the standard formatting methods of the DateTime object.
  14.  
  15. string printDate = dateTime.ToShortDateString() +" "+ dateTime.ToShortTimeString();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.