fork(43) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. //5:00 -> RoundDown() -> 5:00
  8. //5:04 -> RoundDown() -> 5:00
  9. //5:09 -> RoundDown() -> 5:00
  10. //5:10 -> RoundDown() -> 5:10
  11.  
  12. //4:00 -> RoundUp() -> 4:00
  13. //4:50 -> RoundUp() -> 4:50
  14. //4:51 -> RoundUp() -> 5:00
  15. //4:56 -> RoundUp() -> 5:00
  16.  
  17. Console.WriteLine(Round(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 5, 0, 0), 0));
  18. Console.WriteLine(Round(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 5, 4, 0), 0));
  19. Console.WriteLine(Round(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 5, 9, 0), 0));
  20. Console.WriteLine(Round(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 5, 10, 0), 0));
  21. Console.WriteLine(Round(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 4, 0, 0), 1));
  22. Console.WriteLine(Round(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 4, 50, 0), 1));
  23. Console.WriteLine(Round(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 4, 51, 0), 1));
  24. Console.WriteLine(Round(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 4, 56, 0), 1));
  25. }
  26.  
  27. // Define other methods and classes here
  28. public static DateTime Round(DateTime dt, int dir)
  29. {
  30. // dir 1 = up, dir 0 = down
  31. DateTime t;
  32. if (dir == 1)
  33. t = dt.AddMinutes((60 - dt.Minute) % 10);
  34. else
  35. t = dt.AddMinutes(-dt.Minute % 10);
  36. return t;
  37. }
  38. }
Success #stdin #stdout 0.03s 37080KB
stdin
Standard input is empty
stdout
7/6/2012 5:00:00 AM
7/6/2012 5:00:00 AM
7/6/2012 5:00:00 AM
7/6/2012 5:10:00 AM
7/6/2012 4:00:00 AM
7/6/2012 4:50:00 AM
7/6/2012 5:00:00 AM
7/6/2012 5:00:00 AM