title: Convert string to PowerShell DateTime
body: <p>I have the following string: <code>"02-06-2018 16:25:28"</code>. I need to convert it to a <code>DateTime</code> object. I tried doing this:</p>
  
  
  
  <pre class="lang-bsh prettyprint-override"><code>[DateTime]::ParseExact('02-06-2018 16:25:28', 'dd-MM-yyyy hh:mm:ss', $null)
  </code></pre>
  
  <p>But it did not work:</p>
  
  <blockquote>
    <p>String was not recognized as a valid DateTime.</p>
  </blockquote>
  
  <p>Is there another function other than <code>[DateTime]::ParseExact</code> that supports parsing the string in this fomat <code>dd-MM-yyyy hh:mm:ss</code>? </p>
  
  <p>I'm using PowerShell v5.1.</p>