Wednesday 7 July, 2010

PROPER C# TIMESTAMP TO STRING

  1. double timestamp = 1113211532;
  2. // First make a System.DateTime equivalent to the UNIX Epoch.
  3. System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
  4. // Add the number of seconds in UNIX timestamp to be converted.
  5. dateTime = dateTime.AddSeconds(timestamp);
  6. // The dateTime now contains the right date/time so to format the string,
  7. // use the standard formatting methods of the DateTime object.
  8. string printDate = dateTime.ToShortDateString() +" "+ dateTime.ToShortTimeString();

No comments:

Post a Comment