Kad*_*ddy 1 java calendar blackberry date java-me
我从用户那里得到一个日期输入..在这种情况下,我需要确定用户输入的年份是否是闰年...并且在用户输入整个日期即月份日期和年份之后......我需要检查日期是否确实有效,如果是,需要确定该特定日期的日期..有人可以告诉我如何做到这一点.
/* Returns true if the given year is a leap year */
static bool IsLeapYear(int year)
{
if ((year % 400) == 0)
return true;
if ((year % 100) == 0)
return false;
if ((year % 4) == 0)
return true;
return false;
}
Run Code Online (Sandbox Code Playgroud)
2.6. What day of the week was 2 August 1953?
--------------------------------------------
To calculate the day on which a particular date falls, the following
algorithm may be used (the divisions are integer divisions, in which
remainders are discarded):
a = (14 - month) / 12
y = year - a
m = month + 12*a - 2
For Julian calendar: d = (5 + day + y + y/4 + (31*m)/12) mod 7
For Gregorian calendar: d = (day + y + y/4 - y/100 + y/400 + (31*m)/12) mod 7
The value of d is 0 for a Sunday, 1 for a Monday, 2 for a Tuesday, etc.
Example: On what day of the week was the author born?
My birthday is 2 August 1953 (Gregorian, of course).
a = (14 - 8) / 12 = 0
y = 1953 - 0 = 1953
m = 8 + 12*0 - 2 = 6
d = (2 + 1953 + 1953/4 - 1953/100 + 1953/400 + (31*6)/12) mod 7
= (2 + 1953 + 488 - 19 + 4 + 15 ) mod 7
= 2443 mod 7
= 0
I was born on a Sunday.
阅读日历常见问题解答以获取更多信
| 归档时间: |
|
| 查看次数: |
632 次 |
| 最近记录: |