Datetime Formatting in Powershell


In Powershell, you can format datetime with .NET style. You can find all kinds of formating style with ” Custom Date and Time Format Strings”:
http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx


$date= Get-Date
$format =  "d", "f", "F", "g",  "m", "M", "t", "y", 
"dddd, MMMM dd yyyy","M/yy","MM-dd-yy"
foreach ($item in $format ) {
"DATE with $item : {0}" -f $date.ToString($item)
}

 

Reference:
http://powershell.com/cs/blogs/ebookv2/archive/2012/03/20/chapter-13-text-and-regular-expressions.aspx

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s