Converting seconds to an appropriate string description


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



Copy this code and paste it in your HTML
  1. namespace Kyrathasoft.Conversions.GetDurationDescription {
  2.  
  3. using System;
  4.  
  5. public static class clsGetDurationDesc {
  6.  
  7. public static string getDurationDesc(double numMilliseconds) {
  8.  
  9. const double Minute = 60000;
  10. const double Second = 1000;
  11.  
  12. double duration = 0;
  13. string result = string.Empty;
  14.  
  15. if (numMilliseconds >= Minute) {
  16. duration = numMilliseconds / Minute;
  17. //result = String.Format("{0:0.00}", duration) + " minutes";
  18. result = duration.ToString("N3") + " minutes";
  19. }
  20. else {
  21. if (numMilliseconds >= Second) {
  22. duration = numMilliseconds / Second;
  23. //result = String.Format("{0:00}", duration) + " seconds";
  24. result = duration.ToString("N3") + " seconds";
  25. }
  26. else {
  27. result = numMilliseconds.ToString() + " milliseconds";
  28. }
  29. }
  30.  
  31. return result;
  32. }
  33.  
  34.  
  35. }
  36. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.