Home Web Front-end JS Tutorial Datetime package_time and date to determine whether it is a leap year under Javascript

Datetime package_time and date to determine whether it is a leap year under Javascript

May 16, 2016 pm 06:17 PM
datetime leap year

Let’s take a look at the source code:

Copy the code The code is as follows:

/**
* jscript.datetime package
* This package contains utility functions for working with dates and times.
* /
/*namespace*/
if (typeof jscript == 'undefined') {
jscript = function() { }
}

jscript.datetime = function( ) { }

/**
* This function will return the number of days in a given month and year,
* taking leap years into account.
*
* @param inMonth The month, where January = 1 and December = 12.
* @param inYear The year to check the month in.
* @return The number of days in the specified month and year.
*/
jscript.datetime.getNumberDaysInMonth = function(inMonth, inYear) {

inMonth = inMonth - 1;
var leap_year = this.isLeapYear(inYear);
if (leap_year) {
leap_year = 1;
} else {
leap_year = 0;
}
/*4, 6, 9 , November is 30 days, note the above inMonth = inMonth - 1*/
if (inMonth == 3 || inMonth == 5 || inMonth == 8 || inMonth == 10) {
return 30;
} else if (inMonth == 1) {/*2 month has 28 or 29 days, depending on whether it is a leap year*/
return 28 leap_year;
} else {/*Other months Then it is 31 days*/
return 31;
}

} // End getNumberDaysInMonth().


/**
* This function will determine if a given year is a leap year.
* (This function is used to determine whether it is a leap year)
* @param inYear The year to check.
* @return True if inYear is a leap year, false if not.
*/
jscript.datetime.isLeapYear = function(inYear) {

if ((inYear % 4 == 0 && !(inYear % 100 == 0)) || inYear % 400 == 0) {
return true;
} else {
return false;
}

} // End isLeapYear().
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to convert DateTime to integer in Python? How to convert DateTime to integer in Python? Sep 05, 2023 pm 10:21 PM

The manipulation of date and time values ​​is an important aspect of programming, and the Python language provides a useful built-in module for this called datetime. However, in some cases, you may need to convert a DateTime object to an integer value in order to perform specific operations or calculations. There are multiple ways to convert a DateTime to an integer in Python, each with its own advantages and disadvantages. In this article, we'll take a closer look at these methods and examine when each method is appropriate to use. After reading this article, you will have a complete understanding of how to efficiently convert DateTime objects to integers in Python and be able to choose the most appropriate method for your specific programming task. Method 1: Use timestamp

Get today's date using DateTime.Today function in C# Get today's date using DateTime.Today function in C# Nov 18, 2023 pm 12:41 PM

Getting today's date using DateTime.Today function in C# requires specific code examples C# is an object-oriented programming language that provides many built-in classes and methods to handle dates and times. Among them, the DateTime class has some very useful methods, such as the Today property, which can be used to obtain today's date. Here is a sample code that demonstrates how to get today's date using the DateTime.Today function in C#: usingSystem;

How to determine leap year in php? Introduction to three methods How to determine leap year in php? Introduction to three methods Mar 28, 2023 pm 03:45 PM

A leap year refers to a leap year that occurs every four years in the Gregorian calendar, that is, a year of 366 days is inserted between ordinary 365-day years. Its purpose is to conform to the solar year. According to the provisions of the Gregorian calendar, there are generally two situations in leap years: ① the year is evenly divisible by 4, but not 100; ② the year is evenly divisible by 400. In this article, we will introduce to you the method of realizing leap year judgment based on PHP programming language.

How to use DateTime in Python How to use DateTime in Python Apr 19, 2023 pm 11:55 PM

All data are automatically assigned a "DOB" (Date of Birth) at the beginning. Therefore, it is inevitable to encounter date and time data when processing data at some point. This tutorial will take you through the datetime module in Python and using some peripheral libraries such as pandas and pytz. In Python, anything related to date and time is handled by the datetime module, which further divides the module into 5 different classes. Classes are simply data types that correspond to objects. The following figure summarizes the 5 datetime classes in Python along with commonly used attributes and examples. 3 useful snippets 1. Convert string to datetime format, maybe using datet

Write a program in C language to check if a given year is a leap year or not Write a program in C language to check if a given year is a leap year or not Sep 20, 2023 pm 03:33 PM

A leap year has 366 days, while an ordinary year has 365 days. The task is to check whether a given year is a leap year through a program. The logic of the judgment can be implemented by checking whether the year is divisible by 400 or 4, but if it is not divisible by these two numbers, it is an ordinary year. ExampleInput-:year=2000Output-:2000isaLeapYearInput-:year=101Output-:101isnotaLeapyear algorithmStartStep1->declarefunctionbooltocheckifyearifaleapyearornotboolcheck(intye

Use the DateTime.AddDays function in C# to add a specified number of days to a date Use the DateTime.AddDays function in C# to add a specified number of days to a date Nov 18, 2023 pm 03:08 PM

Use the DateTime.AddDays function in C# to add a specified number of days to a date. In C# programming, we often encounter situations where we need to add and subtract dates. The DateTime class in C# provides many convenient methods and properties for working with dates and times, including the AddDays function, which can be used to add a specified number of days to a specified date. Here is a specific code example that demonstrates how to use the DateTime.AddDays function to add a specified number of days to a date:

What are the options for calendar and date libraries in Python? What are the options for calendar and date libraries in Python? Oct 21, 2023 am 09:22 AM

There are many excellent calendar libraries and date libraries in Python for us to use. These libraries can help us handle date and calendar related operations. Next, I will introduce you to several common choices and provide corresponding code examples. Datetime library: Datetime is Python's built-in date and time processing module. It provides many date and time related classes and methods, which can be used to process dates, times, time differences and other operations. Sample code: importdatetime#Get the current date

What to do if mysql datetime error occurs What to do if mysql datetime error occurs Feb 15, 2023 am 10:12 AM

Solution to mysql datetime error: 1. Change datetime to timestamp timestamp; 2. Upgrade MySQL to a higher version; 3. Execute the "ALTER USER 'root'@'localhost' IDENTIFIED BY 'root1' PASSWORD EXPIRE NEVER;" command That’s it.

See all articles