常用日期格式

1.    (get-date -Format 'R') -replace '(?i)[a-z]{3},s([0-9]{2})s([a-z]{3})s([0-9]{4})s.*', '$2-$1-$3'
May-19-2014
 
2.    (get-date -Format 'R').substring(5,11) -replace 's', '-'
19-May-2014
 
3.    (get-date -Format 'R').split(' ')[1,2,3] -join '-'
19-May-2014
 
4.    (get-date).Tostring("dd-MMM-yyyy")
19-5月-2014
 
$date= Get-Date
foreach ($format in "d","D","f","F","g","G","m","r","s","t","T","u","U","y","dddd, MMMM dd yyyy","M/yy","dd-MM-yy") { 
"DATE with $format:{0}" -f $date.ToString($format)
}
 
DATE with d : 2015/5/6
DATE with D : 2015年5月6日
DATE with f : 2015年5月6日 16:42
DATE with F : 2015年5月6日 16:42:06
DATE with g : 2015/5/6 16:42
DATE with G : 2015/5/6 16:42:06
DATE with m : 5月6日
DATE with r : Wed, 06 May 2015 16:42:06 GMT
DATE with s : 2015-05-06T16:42:06
DATE with t : 16:42
DATE with T : 16:42:06
DATE with u : 2015-05-06 16:42:06Z
DATE with U : 2015年5月6日 8:42:06
DATE with y : 2015年5月
DATE with dddd, MMMM dd yyyy : 星期三, 五月 06 2015
DATE with M/yy : 5/15
DATE with dd-MM-yy : 06-05-15
原文地址:https://www.cnblogs.com/IvanChen/p/4492369.html