Search⌘ K
AI Features

Solution: Flight Duration Tracker

Explore how to use C#'s DateTime and TimeSpan structures to calculate flight durations accurately. Learn to extract hours and minutes from time intervals and format them into user-friendly strings, enhancing your skills in date and time manipulation.

We'll cover the following...
C# 14.0
namespace Aviation;
public class FlightTracker
{
public static string GetFlightDurationString(DateTime takeoff, DateTime landing)
{
TimeSpan flightDuration = landing - takeoff;
return $"{flightDuration.Hours} hours and {flightDuration.Minutes} minutes";
}
}
...