Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Task5
- {
- public class Program
- {
- static void Main(string[] args)
- {
- ConvertTo12HourFormat(14, 30);
- ConvertTo12HourFormat(0, 45);
- ConvertTo12HourFormat(12, 0);
- ConvertTo12HourFormat(23, 59);
- ConvertTo12HourFormat(1, 5);
- }
- static void ConvertTo12HourFormat(int hours, int minutes)
- {
- if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59)
- {
- Console.WriteLine("Некорректное время.");
- return;
- }
- string period = hours < 12 ? "AM" : "PM";
- int hour12 = hours % 12;
- if (hour12 == 0)
- {
- hour12 = 12;
- }
- Console.WriteLine($"{hour12}:{minutes:D2} {period}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement