title: DateTime Format - Any System Datetime.now to "DD/MM/YYYY hh:mm:ss"
body: <p>I have a program that do several things. 
  Two of them is <strong>read a date from a txt</strong> and <strong>rewrite a date in the same txt</strong>.</p>
  
  <p>The read of the date is a regex expression like:</p>
  
  <pre><code>[0-9]{2}/[0-9]{2}/[0-9]{4} [0-9]{2}:[0-9]{2}:[0-5]{1}[0-9]{1})
  </code></pre>
  
  <p>The problem is that my regex expression only works in the format 
  "DD/MM/YYYY hh:mm:ss" and its impossible to make sure my regex expression can match all system datetime formats.</p>
  
  <p>So, I need to make sure my program run's in every system, regardless the system datetime.now.
  For that, i thought about format every system datetime.now, at start, to the format mentioned "DD/MM/YYYY hh:mm:ss". </p>
  
  <p>At the moment i have the following code:</p>
  
  <pre><code>Datetime currentDate = DateTime.ParseExact(DateTime.Now.ToString(), "DD/MM/YYYY hh:mm:ss", CultureInfo.InvariantCulture);
  </code></pre>
  
  <p>However, when running some tests, using a system date in format "D/M/YYYY h:m:s" i get the error:</p>
  
  <p><strong>"String was not recognized as a valid DateTime."</strong></p>
  
  <p>The problem is that if my date, for example, is "9/27/2019 04:26:46"(M/D/YYYY h:m:s) it can't fit in the format i defined.</p>
  
  <p>Any idea? 
  Thank you in advance!</p>