[英]Change of format Get-Date` PowerShell
How to do Get-Date
to show me this format 2018-01-10 and that does not show the time? 如何执行Get-Date
向我显示此格式2018-01-10,但不显示时间?
I was currently using Get-Format s
but it shows me time. 我当前正在使用Get-Format s
但是它显示了我的时间。
There are several ways to do this. 有几种方法可以做到这一点。 For instance you could use the -Format
parameter of the cmdlet: 例如,您可以使用cmdlet的-Format
参数:
Get-Date -Format 'yyyy-MM-dd'
You could use the ToString()
method of the DateTime
object the cmdlet produces: 您可以使用cmdlet生成的DateTime
对象的ToString()
方法:
(Get-Date).ToString('yyyy-MM-dd')
You could also use PowerShell's format operator ( -f
): 您还可以使用PowerShell的格式运算符( -f
):
'{0:yyyy-MM-dd}' -f (Get-Date)
其他方法(无获取日期):
[System.DateTime]::Today.ToString("yyyy-MM-dd")
Powershell Script to get date as requested Powershell脚本按要求获取日期
get-date -Format yyyy-MM-dd
Following doc will give you brief explanation on formats 以下文档将为您简要说明格式
https://technet.microsoft.com/en-us/library/ee692801.aspx https://technet.microsoft.com/zh-CN/library/ee692801.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.