Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. private string FormatTime(string hourSeparator)
  2. {
  3. // double currentTimeZone = TimeZoneInfo.Local.BaseUtcOffset.TotalHours;
  4. // Console.WriteLine(offset + " " + currentTimeZone + " (" + (offset + currentTimeZone) + ")");
  5.  
  6. DateTime time = DateTime.UtcNow.AddHours(offset);
  7. time = DateTime.Now.AddHours(offset);
  8.  
  9. string DayNum = time.ToString("dd");
  10. string ShortDay = time.ToString("ddd");
  11. string LongDay = time.ToString("dddd");
  12. string IntMonth = time.ToString("MM");
  13. string ShortMonth = time.ToString("MMM");
  14. string LongMonth = time.ToString("MMMM");
  15. string Year = time.ToString("yyyy");
  16.  
  17. string useColonOrH = hourSeparator;
  18.  
  19. string Hour = time.ToString("hh");
  20.  
  21. if (militaryTime)
  22. {
  23. Hour = time.ToString("HH");
  24. }
  25. else
  26. {
  27. Hour = time.ToString("hh");
  28. if (Hour[0] == '0')
  29. {
  30. Hour = Hour[1].ToString();
  31. }
  32. }
  33.  
  34. string Minute = DateTime.Now.ToString("mm");
  35. string Second = DateTime.Now.ToString("ss");
  36. string AMPM = DateTime.Now.ToString("tt");
  37.  
  38. //if (offset != 0)
  39. //{
  40. // AMPM = DateTime.Now.AddHours(offset).ToString("tt");
  41. //}
  42.  
  43. if (militaryTime)
  44. {
  45. AMPM = "";
  46. }
  47.  
  48. //formatIndex = 3;
  49.  
  50. switch (formatIndex)
  51. {
  52. // Long Month, Day, Year
  53. // Day, Longmonth, Year
  54.  
  55. // Short Month, Day, Year
  56. // Day, Shortmonth, Year
  57.  
  58. // IntMonth, Daynum, Year
  59. // Daynum, Intmonth, Year
  60.  
  61. // Time no seconds
  62.  
  63. case 1:
  64. _monthType = MonthType.Long;
  65. return LongMonth + " " + DayNum + ", " + Year;
  66. case 2:
  67. _monthType = MonthType.Long;
  68. return LongMonth + " " + DayNum + ", " + Year + " " + Hour + useColonOrH + Minute + " " + AMPM;
  69. case 3:
  70. _monthType = MonthType.Long;
  71. return LongMonth + " " + DayNum + ", " + Year + " " + Hour + useColonOrH + Minute + ":" + Second + " " + AMPM;
  72. case 4:
  73. _monthType = MonthType.Long;
  74. return DayNum + " " + LongMonth + ", " + Year;
  75. case 5:
  76. _monthType = MonthType.Long;
  77. return DayNum + " " + LongMonth + ", " + Year + " " + Hour + useColonOrH + Minute + " " + AMPM; ;
  78. case 6:
  79. _monthType = MonthType.Long;
  80. return DayNum + " " + LongMonth + ", " + Year + " " + Hour + useColonOrH + Minute + ":" + Second + " " + AMPM;
  81. case 7:
  82. _monthType = MonthType.Int;
  83. return IntMonth + "/" + DayNum + "/" + Year;
  84. case 8:
  85. _monthType = MonthType.Int;
  86. return IntMonth + "/" + DayNum + "/" + Year + " " + Hour + useColonOrH + Minute + " " + AMPM;
  87. case 9:
  88. _monthType = MonthType.Int;
  89. return IntMonth + "/" + DayNum + "/" + Year + " " + Hour + useColonOrH + Minute + ":" + Second + " " + AMPM;
  90. case 10:
  91. _monthType = MonthType.Int;
  92. return DayNum + "/" + IntMonth + "/" + Year;
  93. case 11:
  94. _monthType = MonthType.Int;
  95. return DayNum + "/" + IntMonth + "/" + Year + " " + Hour + useColonOrH + Minute + " " + AMPM;
  96. case 12:
  97. _monthType = MonthType.Int;
  98. return DayNum + "/" + IntMonth + "/" + Year + " " + Hour + useColonOrH + Minute + ":" + Second + " " + AMPM;
  99. case 13:
  100. _monthType = MonthType.None;
  101. return Hour + ":" + Minute + " " + AMPM;
  102. case 14:
  103. _monthType = MonthType.Short;
  104. return ShortMonth + " " + DayNum + ", " + Year;
  105. case 15:
  106. _monthType = MonthType.Short;
  107. return ShortMonth + " " + DayNum + ", " + Year + " " + Hour + useColonOrH + Minute + " " + AMPM;
  108. default:
  109. case 16:
  110. _monthType = MonthType.Short;
  111. return ShortMonth + " " + DayNum + ", " + Year + " " + Hour + useColonOrH + Minute + ":" + Second + " " + AMPM;
  112. case 17:
  113. _monthType = MonthType.Short;
  114. return DayNum + " " + ShortMonth + ", " + Year;
  115. case 18:
  116. _monthType = MonthType.Short;
  117. return DayNum + " " + ShortMonth + ", " + Year + " " + Hour + useColonOrH + Minute + " " + AMPM;
  118. case 19:
  119. _monthType = MonthType.Short;
  120. return DayNum + " " + ShortMonth + ", " + Year + " " + Hour + useColonOrH + Minute + ":" + Second + " " + AMPM;
  121. case 20:
  122. _monthType = MonthType.None;
  123. return Hour + ":" + Minute + ":" + Second + " " + AMPM;
  124. }
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement