ActiveUp.Net.Mail.Parser.ParseAsUniversalDateTime C# (CSharp) Method

ParseAsUniversalDateTime() public static method

public static ParseAsUniversalDateTime ( string input ) : System.DateTime
input string
return System.DateTime
		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;
		}
		private static string ReplaceTimeZone(string input)

Usage Example

コード例 #1
0
ファイル: Parserv1.cs プロジェクト: angew74/GestionePEC
        public static TraceInfoCollection ParseTraces(string[] input)
        {
            string itemlow;
            TraceInfoCollection traceinfos = new TraceInfoCollection();
            TraceInfo traceinfo = new TraceInfo();
            try
			{
                foreach (string item in input)
                {
                    traceinfo = new TraceInfo();
                    //item = " " + Parser.Clean(item1);
                    itemlow = item.ToLower();
                    if (itemlow.IndexOf(" from ") != -1) traceinfo.From = item.Substring(itemlow.IndexOf(" from ") + 6, item.IndexOf(" ", itemlow.IndexOf(" from ") + 6) - (itemlow.IndexOf(" from ") + 6)).TrimEnd(';');
                    if (itemlow.IndexOf(" by ") != -1) traceinfo.By = item.Substring(itemlow.IndexOf(" by ") + 4, item.IndexOf(" ", itemlow.IndexOf(" by ") + 4) - (itemlow.IndexOf(" by ") + 4)).TrimEnd(';');
                    if (itemlow.IndexOf(" for ") != -1) traceinfo.For = item.Substring(itemlow.IndexOf(" for ") + 5, item.IndexOf(" ", itemlow.IndexOf(" for ") + 5) - (itemlow.IndexOf(" for ") + 5)).TrimEnd(';');
                    if (itemlow.IndexOf(" id ") != -1) traceinfo.Id = item.Substring(itemlow.IndexOf(" id ") + 4, item.IndexOf(" ", itemlow.IndexOf(" id ") + 4) - (itemlow.IndexOf(" id ") + 4)).TrimEnd(';');
                    if (itemlow.IndexOf(" via ") != -1) traceinfo.Via = item.Substring(itemlow.IndexOf(" via ") + 5, item.IndexOf(" ", itemlow.IndexOf(" via ") + 5) - (itemlow.IndexOf(" via ") + 5)).TrimEnd(';');
                    if (itemlow.IndexOf(" with ") != -1) traceinfo.With = item.Substring(itemlow.IndexOf(" with ") + 6, item.IndexOf(" ", itemlow.IndexOf(" with ") + 6) - (itemlow.IndexOf(" with ") + 6)).TrimEnd(';');
                    traceinfo.Date = Parser.ParseAsUniversalDateTime(item.Split(';')[item.Split(';').Length - 1].Trim(' '));
                    traceinfos.Add(traceinfo);
                }
			}
			catch { };
            return traceinfos;
        }
All Usage Examples Of ActiveUp.Net.Mail.Parser::ParseAsUniversalDateTime