There is a Get-date cmdlet in PowerShell that you can use to return the current date and time directly. Use the-format parameter to return the current year, month, day, time, minutes, seconds, and so on.
Direct use of Get-date
Call Get-date directly in PowerShell, and you can return the current date and time, including year, month, day, time, minutes, and seconds. Examples are as follows:
Copy Code code as follows:
PS c:\users\zhanghong> Get-date
September 9, 2013 22:26:56
Use Get-date in Write-host
Note: Using Get-date in Write-host, we can only get a string with the content "get-date", the effect is as follows:
Copy Code code as follows:
PS c:\users\zhanghong> write-host "get-date, helllo!"
Get-date, helllo!
If you want to output the current time in Write-host, you can use the get-date as a variable, using "$ ()" to get it. Use the following methods:
Copy Code code as follows:
PS c:\users\zhanghong> write-host "$ (get-date), hello!"
09/09/2013 22:29:41, hello!
Use the format parameter to get year, month, day, hour, minute, second
Let's see how to use the-format parameter to get the year, month, day, time, minute, and second in Get-date. Remember one of the following relationships first:
Copy Code code as follows:
YYYY years
M Month
D-Day
H-hour (12-hour system)
H-hour (24-hour system)
M minutes
s seconds
Then take a look at the examples to understand:
Copy Code code as follows:
PS c:\users\zhanghong> get-date-format ' yyyy '
2013
About PowerShell use Get-date this cmdlet to get the date and time, small series on the introduction so much, hope to help everyone.