c# - DateTime.Parse always throws exception in a specific culture -


i have old log files have parse - apparently date time saved like: 18/12/2012 11:09:39 p.m. - attempts parse these have failed. lost on - or direction great!

 cultureinfo cultureinfo = new cultureinfo( "es-mx" , true );         string date = "18/12/2012 11:09:39 p.m.";          datetime dt = new datetime( 2012 , 12 , 18 , 11 , 9 , 39 ).addhours( 12 );          this.richtextbox1.text += date + environment.newline;         this.richtextbox1.text += dt.tostring( cultureinfo ) + environment.newline;         this.richtextbox1.text += dt.tostring() + environment.newline;          foreach ( var item in richtextbox1.lines )         {             try             {                datetime d=  datetime.parse( item );                this.richtextbox1.text += d.tostring() + environment.newline ;              }             catch ( exception ee)             {                 this.richtextbox1.text += ee.message + environment.newline ;              }         } 

some dates correct in log file(s) have odd formatting end in p. m. or p.m.. methods above seem fail - , yes tried them :( hack/fix problem:

     cultureinfo cultureinfo = new cultureinfo( "es-mx" , true );      date = datetime.parse( date.replace( "p. m." , "pm" ).replace( "p.m." , "pm" ).replace( "." , "" ).toupper() , cultureinfo ); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -