Using the JS scripting language switch to implement a request a date is the day of the year, consider the run-year

Source: Internet
Author: User

Using the JS scripting language to implement a request a date is the day of the year, consider the run-year

We need to enter the date in the page popup, the code is as follows:

<! DOCTYPE html>

<meta charset= "UTF-8" >

<title></title>

<body>

<!--

Calculate by switch structure A date is the day of the year, consider the year

-

<script type= "Text/javascript" >

var y =parseint (Prompt ("Please enter the Year");

var m = parseint (Prompt ("Please enter Month"));

var d =parseint (Prompt ("Please enter the number");

var sum = 0

Switch (m-1) {

Case 11:

sum + = 30;

Case 10:

sum + = 31;

Case 9:

sum + = 30;

Case 8:

sum + = 31;

Case 7:

sum + = 31;

Case 6:

sum + = 30;

Case 5:

sum + = 31;

Case 4:

sum + = 30;

Case 3:

sum + = 31;

Case 2:

if ((y% 4 = = 0 && y% 100! = 0) | | (y% 400 = = 0)) {

sum + = 29;

}

else{

sum + = 28;

}

Case 1:

sum + = 31;

sum + = D;

Break

Default:

sum = d

}

alert (sum)

</script>

</body>

The results are as follows:


Using the JS scripting language switch to implement a request a date is the day of the year, consider the run-year

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.