I have this value 2016-01-15 19:31:24
That value is $array[0]
I convert it by
$time = [DateTime]::Parse($array[0])
with the result
Friday, January 15, 2016 7:31:24 PM
When I assign Time in a html $body string. I get the initial value. ( 2016-01-15 19:31:24)
Is there something I am not doing?
No. Internally, it’s all stored as a fractional number. In different situations, it’ll get formatted differently. You just need to specify the format you want. There are methods of a DateTime object that produce various formats. What you’re after is probably a “long date time.”
PowerShell’s format commands behave differently than when a DateTime object is just cast to a string (or when its ToString() method is called with no arguments). If you do “$date”, then it’s the latter, casting behavior that is used. When you just do $date and let PowerShell display the value, it goes through PowerShell’s formatting system.
Anyhow, this probably does what you’re after: “My date is: $($date.ToString(‘F’))”
Time zone stuff can be a little bit tricky. First you have to know what your original string represents: “2016-01-15 19:31:24”. Is that local time? Zulu time? Something else?