8,330 questions
Fixed:
$dateString = "Thu Oct 31 04:53:49 +0100 2024"
# Remove the day of the week and timezone
$intermediateDateString = $dateString -replace '^\w{3} ', '' -replace ' \+\d{4}', ''
# Parse the intermediate date string
try {
$parsedDate = [datetime]::ParseExact($intermediateDateString, "MMM dd HH:mm:ss yyyy", [System.Globalization.CultureInfo]::InvariantCulture, [System.Globalization.DateTimeStyles]::None)
# Convert to the desired format
$FileCreateDate = $parsedDate.ToString("dd-MM-yyyy HH:mm:ss")
} catch {
$FileCreateDate = ""
Write-Host "Failed to parse the date string: $($intermediateDateString)"
}