BASIC4MCU | C언어 | C언어 | Determination of the day of the week
페이지 정보
작성자 키트 작성일2017-09-12 13:23 조회1,054회 댓글0건본문
Determination of the day of the week
From Wikipedia, the free encyclopediaThere are various methods to calculate the day of the week for any particular date in the past or future. These methods ultimately rely onalgorithms to determine the day of the week for any given date, including those based solely on tables as found in perpetual calendars that require no calculations to be performed by the user. A typical application is to calculate the day of the week on which someone was born or any other specific event occurred.
Contents
[hide]
Introduction[edit]
To determine the day of the week from numerical operations, Sunday to Saturday is represented as numbers (usually from 0 to 6, respectively, which is equivalent to ISO 8601's alternative usage of 1 = Monday to 7 = Sunday). This is achieved with arithmetic modulo 7. Modulo 7 is an operation that calculates the remainder of a number being divided by 7. Thus the number 7 is treated as 0, 8 as 1, 9 as 2, 18 as 4 and so on; the interpretation of this being that if Sunday is signified as day 0, then 7 days later (i.e. day 7) is also a Sunday, and day 18 will be the same as day 4, which is a Thursday since this falls 4 days after Sunday.
The basic approach of nearly all of the methods to calculate the day of the week begins by starting from an ‘anchor date’: a known pair (such as January 1, 1800 as a Wednesday), determining the number of days between the known day and the day that you are trying to determine, and using arithmetic modulo 7 to find a new numerical day of the week.
One standard approach is to look up (or calculate, using a known rule) the value of the first day of the week of a given century, look up (or calculate, using a method of congruence) an adjustment for the month, calculate the number of leap years since the start of the century, and then add these together along with the number of years since the start of the century, and the day number of the month. Eventually, one ends up with a day-count on which one applies modulo 7 to determine the day of the week of the date.[1]
Some methods do all the additions first and then cast out sevens, whereas others cast them out at each step, as in Lewis Carroll's method. Either way is quite viable: the former is easier for calculators and computer programs; the latter for mental calculation (it is quite possible to do all the calculations in one's head with a little practice). None of the methods given here perform range checks, so that unreasonable dates will produce erroneous results.
Useful concepts[edit]
Corresponding months[edit]
"Corresponding months" are those months within the calendar year that start on the same day. For example, September and December correspond, because September 1 falls on the same day as December 1. Months can only correspond if the number of days between their first days is divisible by 7, or in other words, if their first days are a whole number of weeks apart. For example, February corresponds to March because February has 28 days, a number divisible by 7, 28 days being exactly four weeks. In a leap year, January and February correspond to different months than in a common year, since February 29 means each subsequent month starts a day later.
The months correspond thus:
For common years:
- January and October.
- February, March and November.
- April and July.
- No month corresponds to August.
For leap years:
- January, April and July.
- February and August.
- March and November.
- No month corresponds to October.
For all years:
- September and December.
- No month corresponds to May or June.
In the months table below, corresponding months have the same number, a fact which follows directly from the definition.
Corresponding years[edit]
There are seven possible days that a year can start on, and leap years will alter the day of the week after February 29. This means that there are 14 configurations that a year can have. All the configurations can be referenced by a Dominical letter. For example, 2015 is acommon year starting on Thursday, meaning that 2015 corresponds to the 2009 calendar year. 2016, on the other hand, is a leap year starting on Friday, meaning that the first two months of the year begin on the same day as they do in 2010 (i.e. January 1 is a Friday and February 1 is a Monday) but because of leap day the last ten months correspond to the last ten months in 2011 (i.e. March 1 is a Tuesday, etc.).
A tabular method to calculate the day of the week[edit]
Basic method for mental calculation[edit]
This method is valid for both the Gregorian calendar and the Julian calendar. Britain and its colonies started using the Gregorian calendar on Thursday, September 14, 1752; the previous day was Wednesday, September 2, 1752 (Old Style). The areas now forming the United States adopted the calendar at different times depending on the colonial power: Spain and France had been using it since 1582, while Russia was still using the Julian calendar when Alaska was purchased from it in 1867.
The formula is
, where:
- d is the day of the month,
- m is the month's number in the months table,
- y is the last two digits of the year, and
- c is the century number.
For a modern Gregorian date, this is 6 if the first two digits of the year are evenly divisible by 4, and subsequent centuries are 4-2-0 (so the century numbers for 2000, 2100, 2200, and 2300 are respectively 6, 4, 2, and 0).
For an old Julian date, this is 6 for 1200, and subsequent centuries subtract 1 until 0, when the next century is 6 (so 1300 is 5, and 1100 is 0).If the result is 0, the date was a Sunday; if 1 it was a Monday, and so on through the week until 6 = Saturday:
Date d Day 01 08 15 22 29 1 Monday 02 09 16 23 30 2 Tuesday 03 10 17 24 31 3 Wednesday 04 11 18 25 4 Thursday 05 12 19 26 5 Friday 06 13 20 27 6 Saturday 07 14 21 28 0 Sunday Months table[edit]
Month m Leap years January 0 6 February 3 2 March 3 April 6 May 1 June 4 July 6 August 2 September 5 October 0 November 3 December 5 Years table[edit]
The year modulo 28 y 00 06 17 23 28 34 45 51 56 62 73 79 84 90 0 01 07 12 18 29 35 40 46 57 63 68 74 85 91 96 1 02 13 19 24 30 41 47 52 58
댓글 0
조회수 1,054등록된 댓글이 없습니다.