experiments/csharp/E021-Nearest5MinuteDateTime/Program.cs

7 lines
298 B
C#
Raw Normal View History

2024-05-04 20:16:52 +00:00
DateTime now = DateTime.Now;
double minutes = Math.Round((now.Hour * 60 + now.Minute) / 5.0) * 5.0;
DateTime nearest5Minute = DateTime.Today + TimeSpan.FromMinutes(minutes);
Console.WriteLine($"The current time is {now}");
Console.WriteLine($"The closest 5-minute marker is {nearest5Minute}");