Obtain the instance programs of the week in PHP

Source: Internet
Author: User

PHP provides a brief introduction to how to get the day of the week, and PHP obtains the code on the day of the week:

The code is as follows: Copy code

1 date ("l ");

2 // you can obtain the week in English, such as Sunday.

3 date ("w ");

4 // you can obtain the number of weeks, for example, 123. Note that 0 is Sunday.

Get Chinese day of the week:

The code is as follows: Copy code

1 $ weekarray = array ("day", "one", "two", "three", "four", "five", "six ");

2 // define an array first

3 echo "week". $ weekarray [date ("w")];

Obtain the specified date:

The code is as follows: Copy code

1 $ weekarray = array ("day", "one", "two", "three", "four", "five", "six ");

2 echo "week". $ weekarray [date ("w", "2011-11-11")];

An instance of your own

The code is as follows: Copy code


<? Php
// Obtain the day of the week in php
Function getWeek ($ unixTime = ''){
$ UnixTime = is_numeric ($ unixTime )? $ UnixTime: time ();
$ Weekarray = array ('day', 'yi', '2', '3', '4', '5', '6 ');
Return 'week'. $ weekarray [date ('W', $ unixTime)];
}
Echo getWeek ();

Or

The code is as follows: Copy code

<? Php
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 ();
?>

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.