The method of judging leap year in PowerShell _powershell

Source: Internet
Author: User

The use of PowerShell can be very convenient to judge a period is not a leap year, as long as a word to fix, isleapyear function, really revolutionary AH!

Small knitting before learning other languages, given a period of time, to judge it is a leap year or excepting, need to write large sections of code to achieve. When C # came out, the problem was resolved, and the DateTime type had a static method: Isleapyear (int year). Use this method to return true or false directly. True represents a leap year and false indicates excepting.

And look at the demo code:

Copy Code code as follows:

PS c:\users\zhanghong> [Datetime]::isleapyear (2013)
False

Do you want to explain it? It's easy. [DateTime] refers to a date and time type, and a double colon (::) is the meaning of calling a static method in PowerShell. The Isleapyear () function is used to judge leap years, excepting. Parameters are given directly to the function as a number.

Well, about PowerShell judge this year is not a leap years is the problem, this article on the introduction so much, I hope to help you, thank you!

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.