Класс для представления даты и времени - C#
Формулировка задачи:
Здравствуйте, знаю что уже было много тем создано с подобным вопросом.
Но начал искать я уже после того, как проделал какую то работу и заново переписывать нет желания.
Хотелось бы найти у себя ошибку или может как то пофиксить мой говнокод:
В принципе все работает нормально, кроме одного, он не учитывает то, что всего 12 месяцев, и когда прибавляю дни, часы, и т.д. уходит за 13 месяцев и т.д. Не знаю как решить эту проблему, подскажите если не сложно.
class DateTime { public DateTime(int year, int month, int day, int hour, int minute, int second) { if (second > 60 || second < 0) { throw new ArgumentException("Seconds must be between 0-60"); } if (minute > 60 || minute < 0) { throw new ArgumentException("Minutes must be between 0-60"); } if (hour > 23 || hour < 0) { throw new ArgumentException("Hours must be between 0-24"); } if (day > 31 || day < 1) { throw new ArgumentException("Days must be at least between 1-31"); } //if (day == 31 && ) //тут потом месяцы вписать //{ // throw new ArgumentException("Days must be at least between 1-31"); //} if (month > 12 || month < 1) { throw new ArgumentException("Month must be between 1-12"); } if (year < 0) { throw new ArgumentException("Years must be positve"); } Second = second; Minute = minute; Hour = hour; Day = day; Month = month; Year = year; } public const int SecondsInYear = 31556926; public const int SecondsInMonth = 2629743; public const int SecondsInDay = 86400; public const int SecondsInHour = 3600; public const int SecondsInMinute = 60; public const int MinutesInYear = 525948; public const int MinutesInMonth = 43829; public const int MinutesInDay = 1440; public const int MinutesInHour = 60; public const int HoursInYear = 8765; public const int HoursInMonth = 730; public const int HoursInDay = 24; public const int MonthInYear = 12; public const int DayInYear = 365; public const int DayInMonth = 31; public int Year { get; private set; } public int Month { get; private set; } public int Day { get; private set; } public int Hour { get; private set; } public int Minute { get; private set; } public int Second { get; private set; } public void ChangeDateTime(int year, int month, int day, int hour, int minute, int second) { if (second > 60 || second < 0) { throw new ArgumentException("Seconds must be between 0-60"); } if (minute > 60 || minute < 0) { throw new ArgumentException("Minutes must be between 0-60"); } if (hour > 23 || hour < 0) { throw new ArgumentException("Hours must be between 0-24"); } if (day > 31 || day < 1) { throw new ArgumentException("Days must be at least between 1-31"); } //if (day == 31 && ) //тут потом месяцы вписать //{ // throw new ArgumentException("Days must be at least between 1-31"); //} if (month > 12 || month < 1) { throw new ArgumentException("Month must be between 1-12"); } if (year < 0) { throw new ArgumentException("Years must be positve"); } Second = second; Minute = minute; Hour = hour; Day = day; Month = month; Year = year; } public void AddSecond(int second) { int plusYear = second / SecondsInYear; second = second - plusYear * SecondsInYear; int plusMonth = second / SecondsInMonth; second = second - plusMonth * SecondsInMonth; int plusDay = second / SecondsInDay; second = second - plusDay * SecondsInDay; int plusHour = second / SecondsInHour; second = second - plusHour * SecondsInHour; int plusMinute = second / SecondsInMinute; second = second - plusMinute * SecondsInMinute; if (second + Second > 59) { plusMinute++; second = second - (60 - Second); } else { second = Second + second; } Year += plusYear; Month += plusMonth; Day += plusDay; Hour += plusHour; Minute += plusMinute; Second = second; } public void AddMinute(int minute) { int plusYear = minute / MinutesInYear; minute = minute - plusYear * MinutesInYear; int plusMonth = minute / MinutesInMonth; minute = minute - plusMonth * MinutesInMonth; int plusDay = minute / MinutesInDay; minute = minute - plusDay * MinutesInDay; int plusHour = minute / MinutesInHour; minute = minute - plusHour * MinutesInHour; if (minute + Minute > 59) { plusHour++; minute = minute - (60 - Minute); } else { minute = Minute + minute; } Year += plusYear; Month += plusMonth; Day += plusDay; Hour += plusHour; Minute = minute; } public void AddHour(int hour) { int plusYear = hour / HoursInYear; hour = hour - plusYear * HoursInYear; int plusMonth = hour / HoursInMonth; hour = hour - plusMonth * HoursInMonth; int plusDay = hour / HoursInDay; hour = hour - plusDay * HoursInDay; if (hour + Hour > 23) { plusDay++; hour = hour - (23 - Hour); } else { hour = Hour + hour; } Year += plusYear; Month += plusMonth; Day += plusDay; Hour = hour; } public void AddDay(int day) { int plusYear = day / DayInYear; day = day - plusYear * DayInYear; int plusMonth = day / DayInMonth; day = day - plusMonth * DayInMonth; switch (Month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: if (day + Day > 31) { plusMonth++; day = day - (31 - Day); } else { day = Day + day; } Year += plusYear; Month += plusMonth; Day = day; break; case 4: case 6: case 9: case 11: if (day + Day > 30) { plusMonth++; day = day - (30 - Day); } else { day = Day + day; } Year += plusYear; Month += plusMonth; Day = day; break; case 2: if (VisYear(Year)) { if (day + Day > 29) { plusMonth++; day = day - (29 - Day); } else { day = Day + day; } Year += plusYear; Month += plusMonth; Day = day; } else { if (day + Day > 28) { plusMonth++; day = day - (28 - Day); } else { day = Day + day; } Year += plusYear; Month += plusMonth; Day = day; } break; } } public bool VisYear(int year) { bool flag = false; if (year % 4 == 0) flag = true; else return flag; if (year % 100 == 0) if (year % 400 != 0) flag = false; return flag; } public void AddMonth(int month) { int plusYear = month / MonthInYear; month = month - plusYear * MonthInYear; if (month + Month > 12) { plusYear++; month = month - (12 - Month); } else { month = Month + month; } Year += plusYear; Month = month; } public void AddYear(int year) { if (year < 0) { throw new ArgumentException("Years must be positve"); } else { year = Year + year; } Year = year; } public void Write() { if (Day < 10 && Month < 10) { if (Hour < 10 && Minute < 10 && Second < 10) { Console.WriteLine("0{0}.0{1}.{2} 0{3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Minute < 10) { Console.WriteLine("0{0}.0{1}.{2} 0{3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Second < 10) { Console.WriteLine("0{0}.0{1}.{2} 0{3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10 && Minute < 10) { Console.WriteLine("0{0}.0{1}.{2} {3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10) { Console.WriteLine("0{0}.0{1}.{2} 0{3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10) { Console.WriteLine("0{0}.0{1}.{2} {3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Minute < 10) { Console.WriteLine("0{0}.0{1}.{2} {3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else { Console.WriteLine("0{0}.0{1}.{2} {3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } } else if (Day < 10) { if (Hour < 10 && Minute < 10 && Second < 10) { Console.WriteLine("0{0}.{1}.{2} 0{3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Minute < 10) { Console.WriteLine("0{0}.{1}.{2} 0{3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Second < 10) { Console.WriteLine("0{0}.{1}.{2} 0{3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10 && Minute < 10) { Console.WriteLine("0{0}.{1}.{2} {3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10) { Console.WriteLine("0{0}.{1}.{2} 0{3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10) { Console.WriteLine("0{0}.{1}.{2} {3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Minute < 10) { Console.WriteLine("0{0}.{1}.{2} {3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else { Console.WriteLine("0{0}.{1}.{2} {3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } } else if (Month < 10) { if (Hour < 10 && Minute < 10 && Second < 10) { Console.WriteLine("{0}.0{1}.{2} 0{3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Minute < 10) { Console.WriteLine("{0}.0{1}.{2} 0{3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Second < 10) { Console.WriteLine("{0}.0{1}.{2} 0{3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10 && Minute < 10) { Console.WriteLine("{0}.0{1}.{2} {3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10) { Console.WriteLine("{0}.0{1}.{2} 0{3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10) { Console.WriteLine("{0}.0{1}.{2} {3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Minute < 10) { Console.WriteLine("{0}.0{1}.{2} {3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else { Console.WriteLine("{0}.0{1}.{2} {3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } } else { if (Hour < 10 && Minute < 10 && Second < 10) { Console.WriteLine("{0}.{1}.{2} 0{3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Minute < 10) { Console.WriteLine("{0}.{1}.{2} 0{3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Second < 10) { Console.WriteLine("{0}.{1}.{2} 0{3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10 && Minute < 10) { Console.WriteLine("{0}.{1}.{2} {3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10) { Console.WriteLine("{0}.{1}.{2} 0{3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10) { Console.WriteLine("{0}.{1}.{2} {3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Minute < 10) { Console.WriteLine("{0}.{1}.{2} {3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else { Console.WriteLine("{0}.{1}.{2} {3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } } } } }
Решение задачи: «Класс для представления даты и времени»
textual
Листинг программы
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace lab1_3sem { class DateTime { // метод для проверки на ошибку ввода public DateTime(int year, int month, int day, int hour, int minute, int second) { if (second > 60 || second < 0) { throw new ArgumentException("Seconds must be between 0-60"); } if (minute > 60 || minute < 0) { throw new ArgumentException("Minutes must be between 0-60"); } if (hour > 23 || hour < 0) { throw new ArgumentException("Hours must be between 0-24"); } if (day > 31 || day < 1) { throw new ArgumentException("Days must be at least between 1-31"); } if (month > 12 || month < 1) { throw new ArgumentException("Month must be between 1-12"); } if (year < 0) { throw new ArgumentException("Years must be positve"); } Second = second; Minute = minute; Hour = hour; Day = day; Month = month; Year = year; } // константы для вычисления public const int SecondsInYear = 31556926; public const int SecondsInMonth = 2629743; public const int SecondsInDay = 86400; public const int SecondsInHour = 3600; public const int SecondsInMinute = 60; public const int MinutesInYear = 525948; public const int MinutesInMonth = 43829; public const int MinutesInDay = 1440; public const int MinutesInHour = 60; public const int HoursInYear = 8765; public const int HoursInMonth = 730; public const int HoursInDay = 24; public const int MonthInYear = 12; public const int DayInYear = 365; public const int DayInMonth = 31; public int Year { get; private set; } public int Month { get; private set; } public int Day { get; private set; } public int Hour { get; private set; } public int Minute { get; private set; } public int Second { get; private set; } // метод для изменения даты public void ChangeDateTime(int year, int month, int day, int hour, int minute, int second) { if (second > 60 || second < 0) { throw new ArgumentException("Seconds must be between 0-60"); } if (minute > 60 || minute < 0) { throw new ArgumentException("Minutes must be between 0-60"); } if (hour > 24 || hour < 0) { throw new ArgumentException("Hours must be between 0-24"); } if (day > 31 || day < 1) { throw new ArgumentException("Days must be at least between 1-31"); } if (month > 12 || month < 1) { throw new ArgumentException("Month must be between 1-12"); } if (year < 0) { throw new ArgumentException("Years must be positve"); } Second = second; Minute = minute; Hour = hour; Day = day; Month = month; Year = year; } // метод для добавления секунд public void AddSecond(int second) { int plusYear = second / SecondsInYear; second = second - plusYear * SecondsInYear; int plusMonth = second / SecondsInMonth; second = second - plusMonth * SecondsInMonth; int plusDay = second / SecondsInDay; second = second - plusDay * SecondsInDay; int plusHour = second / SecondsInHour; second = second - plusHour * SecondsInHour; int plusMinute = second / SecondsInMinute; second = second - plusMinute * SecondsInMinute; if (second + Second > 59) { plusMinute++; second = second - (60 - Second); } else { second = Second + second; } if (Hour + plusHour > 23) { plusHour++; Hour = Hour - (23 - plusHour); } else { Hour += plusHour; } if (Minute + plusMinute > 60) { plusHour++; Minute = Minute - (12 - plusMinute); } else { Minute += plusMinute; } if (Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12) { Day = 31; if (Day + plusDay > 31) { plusMonth++; Day = Day - (31 - plusDay); } else { Day += plusDay; } } if (Month == 4 || Month == 6 || Month == 9 || Month == 11) { Day = 30; if (Day + plusDay > 30) { plusMonth++; Day = Day - (30 - plusDay); } else { Day += plusDay; } } if (Month == 2 && VisYear(Year)) { Day = 29; if (Day + plusDay > 29) { plusMonth++; Day = Day - (29 - plusDay); } else { Day += plusDay; } } else if (Month == 2) { Day = 28; if (Day + plusDay > 28) { plusMonth++; Day = Day - (28 - plusDay); } else { Day += plusDay; } } if (Month + plusMonth > 12) { plusYear++; Month = Month - (12 - plusMonth); } else { Month += plusMonth; } Year += plusYear; Second = second; } // метод для добавления минут public void AddMinute(int minute) { int plusYear = minute / MinutesInYear; minute = minute - plusYear * MinutesInYear; int plusMonth = minute / MinutesInMonth; minute = minute - plusMonth * MinutesInMonth; int plusDay = minute / MinutesInDay; minute = minute - plusDay * MinutesInDay; int plusHour = minute / MinutesInHour; minute = minute - plusHour * MinutesInHour; if (minute + Minute > 59) { plusHour++; minute = minute - (60 - Minute); } else { minute = Minute + minute; } Year += plusYear; if (Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12) { Day = 31; if (Day + plusDay > 31) { plusMonth++; Day = Day - (31 - plusDay); } else { Day += plusDay; } } if (Month == 4 || Month == 6 || Month == 9 || Month == 11) { Day = 30; if (Day + plusDay > 30) { plusMonth++; Day = Day - (30 - plusDay); } else { Day += plusDay; } } if (Month == 2 && VisYear(Year)) { Day = 29; if (Day + plusDay > 29) { plusMonth++; Day = Day - (29 - plusDay); } else { Day += plusDay; } } else if (Month == 2) { Day = 28; if (Day + plusDay > 28) { plusMonth++; Day = Day - (28 - plusDay); } else { Day += plusDay; } } if (Month + plusMonth > 12) { plusYear++; Month = Month - (12 - plusMonth); } else { Month += plusMonth; } if (Hour + plusHour > 23) { plusHour++; Hour = Hour - (23 - plusHour); } else { Hour += plusHour; } Minute = minute; } // метод для добавления часа public void AddHour(int hour) { int plusYear = hour / HoursInYear; hour = hour - plusYear * HoursInYear; int plusMonth = hour / HoursInMonth; hour = hour - plusMonth * HoursInMonth; int plusDay = hour / HoursInDay; hour = hour - plusDay * HoursInDay; if (hour + Hour > 24) { plusDay++; hour = hour - (24 - Hour); } else { hour = Hour + hour; } if (Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12) { Day = 31; if (Day + plusDay > 31) { plusMonth++; Day = Day - (31 - plusDay); } else { Day += plusDay; } } if (Month == 4 || Month == 6 || Month == 9 || Month == 11) { Day = 30; if (Day + plusDay > 30) { plusMonth++; Day = Day - (30 - plusDay); } else { Day += plusDay; } } if (Month == 2 && VisYear(Year)) { Day = 29; if (Day + plusDay > 29) { plusMonth++; Day = Day - (29 - plusDay); } else { Day += plusDay; } } else if (Month == 2) { Day = 28; if (Day + plusDay > 28) { plusMonth++; Day = Day - (28 - plusDay); } else { Day += plusDay; } } if (Month + plusMonth > 12) { plusYear++; Month = Month - (12 - plusMonth); } else { Month += plusMonth; } Year += plusYear; Hour = hour; } // метод для добавления дня public void AddDay(int day) { int plusYear = day / DayInYear; day = day - plusYear * DayInYear; int plusMonth = day / DayInMonth; day = day - plusMonth * DayInMonth; switch (Month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: if (day + Day > 31) { plusMonth++; day = day - (31 - Day); } else { day = Day + day; } if (Month + plusMonth > 12) { plusYear++; Month = Month - (12 - plusMonth); } else { Month += plusMonth; } Year += plusYear; Day = day; break; case 4: case 6: case 9: case 11: if (day + Day > 30) { plusMonth++; day = day - (30 - Day); } else { day = Day + day; } Year += plusYear; if (Month + plusMonth > 12) { plusYear++; Month = Month - (12 - plusMonth); } else { Month += plusMonth; } Day = day; break; case 2: if (VisYear(Year)) { if (day + Day > 29) { plusMonth++; day = day - (29 - Day); } else { day = Day + day; } Year += plusYear; if (Month + plusMonth > 12) { plusYear++; Month = Month - (12 - plusMonth); } else { Month += plusMonth; } Day = day; } else { if (day + Day > 28) { plusMonth++; day = day - (28 - Day); } else { day = Day + day; } Year += plusYear; if (Month + plusMonth > 12) { plusYear++; Month = Month - (12 - plusMonth); } else { Month += plusMonth; } Day = day; } break; } } // метод для проверки на високосный год public bool VisYear(int year) { bool flag = false; if (year % 4 == 0) flag = true; else return flag; if (year % 100 == 0) if (year % 400 != 0) flag = false; return flag; } // метод для изменения месяца public void AddMonth(int month) { int plusYear = month / MonthInYear; month = month - plusYear * MonthInYear; if (month + Month > 12) { plusYear++; month = month - (12 - Month); } else { month = Month + month; } Year += plusYear; Month = month; } // метод для изменения года public void AddYear(int year) { year = Year + year; Year = year; } // метод для вывода все на экран public void Write() { if (Day < 10 && Month < 10) { if (Hour < 10 && Minute < 10 && Second < 10) { Console.WriteLine("0{0}.0{1}.{2} 0{3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Minute < 10) { Console.WriteLine("0{0}.0{1}.{2} 0{3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Second < 10) { Console.WriteLine("0{0}.0{1}.{2} 0{3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10 && Minute < 10) { Console.WriteLine("0{0}.0{1}.{2} {3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10) { Console.WriteLine("0{0}.0{1}.{2} 0{3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10) { Console.WriteLine("0{0}.0{1}.{2} {3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Minute < 10) { Console.WriteLine("0{0}.0{1}.{2} {3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else { Console.WriteLine("0{0}.0{1}.{2} {3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } } else if (Day < 10) { if (Hour < 10 && Minute < 10 && Second < 10) { Console.WriteLine("0{0}.{1}.{2} 0{3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Minute < 10) { Console.WriteLine("0{0}.{1}.{2} 0{3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Second < 10) { Console.WriteLine("0{0}.{1}.{2} 0{3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10 && Minute < 10) { Console.WriteLine("0{0}.{1}.{2} {3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10) { Console.WriteLine("0{0}.{1}.{2} 0{3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10) { Console.WriteLine("0{0}.{1}.{2} {3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Minute < 10) { Console.WriteLine("0{0}.{1}.{2} {3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else { Console.WriteLine("0{0}.{1}.{2} {3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } } else if (Month < 10) { if (Hour < 10 && Minute < 10 && Second < 10) { Console.WriteLine("{0}.0{1}.{2} 0{3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Minute < 10) { Console.WriteLine("{0}.0{1}.{2} 0{3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Second < 10) { Console.WriteLine("{0}.0{1}.{2} 0{3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10 && Minute < 10) { Console.WriteLine("{0}.0{1}.{2} {3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10) { Console.WriteLine("{0}.0{1}.{2} 0{3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10) { Console.WriteLine("{0}.0{1}.{2} {3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Minute < 10) { Console.WriteLine("{0}.0{1}.{2} {3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else { Console.WriteLine("{0}.0{1}.{2} {3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } } else { if (Hour < 10 && Minute < 10 && Second < 10) { Console.WriteLine("{0}.{1}.{2} 0{3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Minute < 10) { Console.WriteLine("{0}.{1}.{2} 0{3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10 && Second < 10) { Console.WriteLine("{0}.{1}.{2} 0{3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10 && Minute < 10) { Console.WriteLine("{0}.{1}.{2} {3}:0{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Hour < 10) { Console.WriteLine("{0}.{1}.{2} 0{3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else if (Second < 10) { Console.WriteLine("{0}.{1}.{2} {3}:{4}:0{5}", Day, Month, Year, Hour, Minute, Second); } else if (Minute < 10) { Console.WriteLine("{0}.{1}.{2} {3}:0{4}:{5}", Day, Month, Year, Hour, Minute, Second); } else { Console.WriteLine("{0}.{1}.{2} {3}:{4}:{5}", Day, Month, Year, Hour, Minute, Second); } } } } }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д