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

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.