datetime - The same Parsing-Pattern for String to Date works once and the other time it fails? -


I download my emails and want them sorted by ACC. To date, some of them are forwarded so that the date of the email is forwarding date, but the original date should be skipped.

Here are the parts of the forwarded email:

+ OK 5522 octet return path: ... id lg7sm19095682wjb.9.2014.08.01.01.02.00 ...
cipher = ECDHE-RSA-RC4-SHA bits = 128/128); ... Friday, 01 Aug 2014 01:02:00 -0700 (PDT) Message ID: ...
Date: Fri, 01 Aug 2014 10:02:04 + 0200 : ...
Content-type: text / plain; Charset = UTF-8; Format = streamed communication-transfer-encoding: 8 bit
-------- origin-nashrich -------- ..... Data: Tuesday, October 22, 2013 18:18:18 +0200 (CeSt) von: ...

If I try to catch the date of the original email (< Strong> Date: Fri, 01 Aug 2014 10:02:04 )
This match and paras work perfectly!

  # ** Date of sending actual email **: Date: Fri, 01 Aug 2014 10:02:04 +0200 if ($ match-match 'date: \ w [e-ja -Z] + \ W + (\ d +. + \ \ D \) [w] \ {$ a = [Datetime] :: Parsexact ($ match [1], " DD MMM yyyy HH: mm: ss ", $ null)} and {$ listOfMails.Add ($ a.ToString (" yyyy.MM.dd-HH: mm: ss "), $ mail); $ N--; Continue}} and {$ n--; Continue}}  

But I try to match and parse the original date of the email, but in reality does it fail?

  # Original date of email: Data: Tuesday, October 22, 2013 18:18:18 ... If ($ Mail Mail 'Basic-Nocchurch. +. Datam * W * [Az] [A-GA-Z] + \ W + (\ D +. +? \ D {4} \ W [\ d:] +) \ W * ') {Write-host "Date 1: & gt; $ ( $ Mail [1]) & lt; " {$ A = [datetime] :: Parsextact ($ match [1], "dd MMM yyyy HH: mm: ss", $ null)} {$ _; Break} $ listOfMails.Add ($ a.ToString ("yyyy.MM.dd -HH: mm: ss"), $ Mail); $ N--; 1) The match is well ($ right)! 
2) List-Host prints: date 1:> 22 October 2013 18:18:18 & lt;
3) The right pattern to parse me would be: 'DD MMM YHH: MM: SS' 4) but it fails ?? 5) PowerShell error message:
Exception. "String was not changed as valid date time" (my translation from German)
BC: \ user \ cass \ document \ sysTools \ PC \ WindowsPowerShell \ Pop3_v2.ps1: Zeechen 168: 50
+ $ a = [datetime] :: Parsexact & lt; & Lt; & Lt; & Lt; ($ Match [1], "DD MMM HH: mm: SS", $ tap)
Information: Not specified: (:) [], Law Invocation Exponence
Fully Qualified Irride: DotNetMetxation

Any idea which causes the problem and what to do? Thank you

PS only had to add this message to me directly from the mail box to the DLD and then parsed.

Solution on my German PC Angle made October the cause of the problem - Okta solved it.

The problem is due to culture. From MSDN, when you call datetime. Percextact:

If the provider is empty, then CultureInfo Object that matches the current culture.

I think your parsing fails because you are using German CultureInfo D-Day . Works well with the same parsing en-US or InvariantCulture .

  PS C: \ & gt; $ S = "22 October 2013 18:18:18" PSC: \ & gt; $ F = "DD MMM YYYY HH: MM: SS" PS C: \ & gt; [Date time]: Parsexact ($ s, $ f, [CultureInfo] :: GetCultureInfo ("de-DE")) with the exception "ParseExact" is called "3" argument: "String a valid date time." On line: 1 character: 1 + [day-time]: parsexact ("22 October 2013 18:18:18", "DD MMM Yay HH: mm: SS", [Culture ... ... ~ ~ ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Category information: Not specified: (:) [], method Invocation Exception + Fully Qualified Irride: Format xpsps ps : \ & Gt; [Day-to-day] :: Purse Ecact ($ s, $ f, [CultureInfo] :: GetCultureInfo ("en-US")) Tuesday, October 22, 2013 18:18:18 PSC: & Gt; [day-time]: Parsexact ($ s, $ Tuesday, 22 October 2013 18:18:18  

I do not know German, so I went to Google translation and found That's the "Oktober" of the German in "October." Now, the following code works:

  PS C: \> [datetime] :: ParseExact ("22 Okt 2013 18 : 18: 18 ", $ f, [CultureInfo] :: GetCultureInfo (" de-DE ")) Tuesday, October 22, 2013 18:18:18  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -