ActiveUp.Net.Mail.Parser.ReplaceTimeZone C# (CSharp) Метод

ReplaceTimeZone() приватный статический Метод

private static ReplaceTimeZone ( string input ) : string
input string
Результат string
		private static string ReplaceTimeZone(string input)
		{
			input = input.Replace("EDT","-0400");
			input = input.Replace("EST","-0500");
			input = input.Replace("CDT","-0500");
			input = input.Replace("CST","-0600");
			input = input.Replace("MDT","-0600");
			input = input.Replace("MST","-0700");
			input = input.Replace("PDT","-0700");
			input = input.Replace("PST","-0800");
			input = input.Replace("UT","+0000");
			input = input.Replace("GMT","+0000");
			return input;
		}
		internal static string RemoveWhiteSpaces(string input)

Usage Example

Пример #1
0
		//End of address parsing.
		//Date parsing conformant to RFC2822 and accepting RFC822 dates.
		public static System.DateTime ParseAsUniversalDateTime(string input)
		{
			input = Parser.ReplaceTimeZone(input);
			input = Parser.Clean(input);
			input = System.Text.RegularExpressions.Regex.Replace(input,@" +"," ");
			input = System.Text.RegularExpressions.Regex.Replace(input,@"( +: +)|(: +)|( +:)",":");
			if(input.IndexOf(",")!=-1) 
			{
				input = input.Replace(input.Split(',')[0]+", ","");
			}
			string[] parts = input.Split(' ');
			int year = System.Convert.ToInt32(parts[2]);
			if(year<100)
			{
				if(year>49) year += 1900;
				else year += 2000;
			}
			int month = Parser.GetMonth(parts[1]);
			int day = System.Convert.ToInt32(parts[0]);
			string[] dateParts = parts[3].Split(':');
			int hour = System.Convert.ToInt32(dateParts[0]);
			int minute = System.Convert.ToInt32(dateParts[1]);
			int second = 0;
			if(dateParts.Length>2) second = System.Convert.ToInt32(dateParts[2]);
			int offset_hours = System.Convert.ToInt32(parts[4].Substring(0,3));
			int offset_minutes = System.Convert.ToInt32(parts[4].Substring(3,2));
			System.DateTime date = new System.DateTime(year,month,day,hour,minute,second);
			date = date.AddHours(-offset_hours);
			date = date.AddMinutes(-offset_minutes);
			return date;
		}