PHP get the day of the Week instance program _php Tutorial

Source: Internet
Author: User
PHP provides us with a large number of functions to get the day of the week, we commonly use the date () function, let me introduce the date of the week to get a specific instance.

PHP date () parameter description

Here the main use of the W this parameter, the explanation of this parameter is:

W represents day of the week, number represents 0 (for Sunday) to 6 (for Saturday)

With this all is very simple, the author here directly affixed to the code, the details do not explain:

Simply getting the day of the week is actually the use of the date function

Date ("L");

Data can be obtained in English for weeks such as Sunday

Date ("W");

This can get the numbers for weeks like 123, note that 0 is Sunday

Get Chinese week can be like this

The code is as follows Copy Code

$weekarray =array ("Day", "one", "two", "three", "four", "five", "six");
echo "Week". $weekarray [Date ("W")];

Gets the specified date:

The code is as follows Copy Code

$weekarray =array ("Day", "one", "two", "three", "four", "five", "six");
echo "Week". $weekarray [Date ("W", "2011-11-11")];

Cases

The code is as follows Copy Code

PHP get today is the day of the week
function Getweek ($unixTime = ") {
$unixTime =is_numeric ($unixTime)? $unixTime: Time ();
$weekarray =array (' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' VI ');
Return ' Week '. $weekarray [Date (' W ', $unixTime)];
}
Echo Getweek ();

Or

function Getweek () {
$week = Date ("W");
Switch ($week) {
Case 1:
return "Monday";
Break
Case 2:
return "Tuesday";
Break
Case 3:
return "Wednesday";
Break
Case 4:
return "Thursday";
Break
Case 5:
return "Friday";
Break
Case 6:
return "Saturday";
Break
Case 0:
return "Sunday";
Break
}
}
echo "Today is:". Getweek ();
?>


PHP's date function has a time range, that is, only from 1970-2038 years, so algorithms outside this range are not allowed. How do you calculate the bottom? In fact, there is a formula:

Caille (Zeller) formula: w=y+[y/4]+[c/4]-2c+[26 (m+1)/10]+d-1

The meanings of the symbols in the formula are as follows, W: week; C: Century -1;y: Year (two digits); M: month (m greater than or equal to 3, less than or equal to 14, that is, in the Caille formula, the December of the year is counted as the previous year's 13, 1 April, For example, January 1, 2003 should be considered as the 2002 1 March 1 to calculate); D: day; [] represents rounding, that is, as long as the integer part. (c is the century minus one, y is two digits after the year, M is the month, and D is the number of days. January and February are calculated according to the previous year's 1 March and 1 April, when both C and Y are valued for the previous year. )

The calculated W divided by 7, the remainder is a few weeks. If the remainder is 0, it is Sunday.

Taking October 1, 2049 (National Day of the 100 anniversary) as an example, the Caille (Zeller) formula is used to calculate the process as follows:
Caille (Zeller) formula: w=y+[y/4]+[c/4]-2c+[26 (m+1)/10]+d-1
=49+[49/4]+[20/4]-2x20+[26x (10+1)/10]+1-1
=49+[12.25]+5-40+[28.6]
=49+12+5-40+28
=54 (divided by more than 7 5)
namely October 1, 2049 (100 Anniversary National Day) is the Week 5.

http://www.bkjia.com/PHPjc/631247.html www.bkjia.com true http://www.bkjia.com/PHPjc/631247.html techarticle PHP provides us with a large number of functions to get the day of the week, we commonly use the date () function, let me introduce the date of the week to get a specific instance. PHP date () parameter description this ...

  • Related Article

    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.