Date and Time Processing for powershell Programming

Source: Internet
Author: User

Date and Time
1. Obtain the system time
Get-Date
Get-date-displayhint time
Get-date-displayhint date
You can also assign get-date to the variable:
$ A = Get-date 5/1/2012
$ B = Get-Date "5/1/2012 8:00 am"
Get-date also includes some methods:
Addseconds, such as Get-Date.AddSeconds (10)
Addminutes
Addhours
Adddays
Addmonths
Addyears

2. Set the system time
Set-date "11/21/2012"
Set-date "11/21/2012 :30 am"
Set-date "11/21/2012 14:25"
Set-date (get-date). adddays (2)
Set-date (get-date). addhours (-1)
Set-date-adjust the system time is adjusted forward for 1 hour

3. Time Calculation
New-timespan
As follows:
New-timespan $ (get-date) $ (get-date-Month 12-day 31-Year-hour 22-minute 20 2012)
Returns the number of days, hours, minutes, And seconds between the two dates.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.