Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private string FormatTime(string hourSeparator)
- {
- // double currentTimeZone = TimeZoneInfo.Local.BaseUtcOffset.TotalHours;
- // Console.WriteLine(offset + " " + currentTimeZone + " (" + (offset + currentTimeZone) + ")");
- DateTime time = DateTime.UtcNow.AddHours(offset);
- time = DateTime.Now.AddHours(offset);
- string DayNum = time.ToString("dd");
- string ShortDay = time.ToString("ddd");
- string LongDay = time.ToString("dddd");
- string IntMonth = time.ToString("MM");
- string ShortMonth = time.ToString("MMM");
- string LongMonth = time.ToString("MMMM");
- string Year = time.ToString("yyyy");
- string useColonOrH = hourSeparator;
- string Hour = time.ToString("hh");
- if (militaryTime)
- {
- Hour = time.ToString("HH");
- }
- else
- {
- Hour = time.ToString("hh");
- if (Hour[0] == '0')
- {
- Hour = Hour[1].ToString();
- }
- }
- string Minute = DateTime.Now.ToString("mm");
- string Second = DateTime.Now.ToString("ss");
- string AMPM = DateTime.Now.ToString("tt");
- //if (offset != 0)
- //{
- // AMPM = DateTime.Now.AddHours(offset).ToString("tt");
- //}
- if (militaryTime)
- {
- AMPM = "";
- }
- //formatIndex = 3;
- switch (formatIndex)
- {
- // Long Month, Day, Year
- // Day, Longmonth, Year
- // Short Month, Day, Year
- // Day, Shortmonth, Year
- // IntMonth, Daynum, Year
- // Daynum, Intmonth, Year
- // Time no seconds
- case 1:
- _monthType = MonthType.Long;
- return LongMonth + " " + DayNum + ", " + Year;
- case 2:
- _monthType = MonthType.Long;
- return LongMonth + " " + DayNum + ", " + Year + " " + Hour + useColonOrH + Minute + " " + AMPM;
- case 3:
- _monthType = MonthType.Long;
- return LongMonth + " " + DayNum + ", " + Year + " " + Hour + useColonOrH + Minute + ":" + Second + " " + AMPM;
- case 4:
- _monthType = MonthType.Long;
- return DayNum + " " + LongMonth + ", " + Year;
- case 5:
- _monthType = MonthType.Long;
- return DayNum + " " + LongMonth + ", " + Year + " " + Hour + useColonOrH + Minute + " " + AMPM; ;
- case 6:
- _monthType = MonthType.Long;
- return DayNum + " " + LongMonth + ", " + Year + " " + Hour + useColonOrH + Minute + ":" + Second + " " + AMPM;
- case 7:
- _monthType = MonthType.Int;
- return IntMonth + "/" + DayNum + "/" + Year;
- case 8:
- _monthType = MonthType.Int;
- return IntMonth + "/" + DayNum + "/" + Year + " " + Hour + useColonOrH + Minute + " " + AMPM;
- case 9:
- _monthType = MonthType.Int;
- return IntMonth + "/" + DayNum + "/" + Year + " " + Hour + useColonOrH + Minute + ":" + Second + " " + AMPM;
- case 10:
- _monthType = MonthType.Int;
- return DayNum + "/" + IntMonth + "/" + Year;
- case 11:
- _monthType = MonthType.Int;
- return DayNum + "/" + IntMonth + "/" + Year + " " + Hour + useColonOrH + Minute + " " + AMPM;
- case 12:
- _monthType = MonthType.Int;
- return DayNum + "/" + IntMonth + "/" + Year + " " + Hour + useColonOrH + Minute + ":" + Second + " " + AMPM;
- case 13:
- _monthType = MonthType.None;
- return Hour + ":" + Minute + " " + AMPM;
- case 14:
- _monthType = MonthType.Short;
- return ShortMonth + " " + DayNum + ", " + Year;
- case 15:
- _monthType = MonthType.Short;
- return ShortMonth + " " + DayNum + ", " + Year + " " + Hour + useColonOrH + Minute + " " + AMPM;
- default:
- case 16:
- _monthType = MonthType.Short;
- return ShortMonth + " " + DayNum + ", " + Year + " " + Hour + useColonOrH + Minute + ":" + Second + " " + AMPM;
- case 17:
- _monthType = MonthType.Short;
- return DayNum + " " + ShortMonth + ", " + Year;
- case 18:
- _monthType = MonthType.Short;
- return DayNum + " " + ShortMonth + ", " + Year + " " + Hour + useColonOrH + Minute + " " + AMPM;
- case 19:
- _monthType = MonthType.Short;
- return DayNum + " " + ShortMonth + ", " + Year + " " + Hour + useColonOrH + Minute + ":" + Second + " " + AMPM;
- case 20:
- _monthType = MonthType.None;
- return Hour + ":" + Minute + ":" + Second + " " + AMPM;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement