Parsing exception calling "Parse" with "2" argument(s): "String was not recognized as a valid DateTime."

Viewed 154

I am trying to parse the Date time from +00 into UK format.

This is the script I'm using:

$rgName = "product1-website"
$accountName = "product1website"

$dtProvider = New-Object -TypeName System.Globalization.CultureInfo -ArgumentList 'en-GB'

$storageAccount = Get-AzStorageAccount -ResourceGroupName $rgName -Name $accountName
$ctx = $storageAccount.Context

Get-AzStorageContainer -Context $ctx | 
    Select-Object Name, 
                  PublicAccess, 
                  LastModified, 
                  @{n = 'LastModifiedTime (Local)'; e = { Try { [DateTime]::Parse("$($_.LastModified)", $dtProvider) } Catch { $_.Exception.Message } } }

and this is the error it throws when the date is converted into MM/dd/yyyy:

enter image description here

How can I just parse and convert the UTC +00 into UTC +1 ?

1 Answers

Try this :

Get-AzStorageContainer -Context $ctx | 
    Select-Object Name, 
                  PublicAccess, 
                  LastModified,
                  @{n = 'LastModifiedTime (Local)'; e = { Try { [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId( $_.LastModified , 'Central European Standard Time') } Catch { $_.Exception.Message } } }

Result(using time zone Central European Standard Time as UTC+1): enter image description here

Related