Formatting a date/time with PowerShell

I have a date/time like the below. I have tried different methods but cannot get it formatted properly. Can someone point me in the right direction?

Current Format
20160801164123.157000+000

Desired Format

yyyyMMdd HH:mm:ss
LorrecAsked:
Who is Participating?
 
oBdAConnect With a Mentor Commented:
([WMI]'').ConvertToDateTime('20160801164123.157000+000').ToString('yyyyMMdd HH:mm:ss')

Open in new window

1
 
aikimarkCommented:
@Lorrec

How important are the fractions of a second in your conversion?  The fractional seconds are being ignored by the posted solution as well as this alternative solution.
[System.Management.ManagementDateTimeConverter]::ToDateTime('20160801164123.157000+000').ToString('yyyyMMdd HH:mm:ss')

Open in new window


Note: I find some of these methods rather verbose.  I prefer something like this:
$DTC=[System.Management.ManagementDateTimeConverter]
$DTC::todatetime('20160801164123.957000+000').ToString('yyyyMMdd HH:mm:ss')

Open in new window

0
 
LorrecAuthor Commented:
Thank you for the assistance. This was helpful.
0
 
LorrecAuthor Commented:
Thank you aikimark for the assistance as well.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.