Dotnet, Development, C Sharp Programming, Csharp, Microsoft.
var currentTime = DateTimeOffset.UtcNow; var message = currentTime.Hour switch { >= 6 and <= 12 => "Morning", > 12 and <= 18 => "Afternoon", > 18 and <= 24 => "Evening", _ => "Night" }; return message; } Note that this method uses the DateTimeOffset.UtcNow. In this case, you will not be able to