PHP to obtain the day of the Week program. In php, we want to obtain the day of the week, which can be operated by using the date function. next I will summarize the specific operation methods for you, I hope this method will be helpful to all of you. in php, you can use the date function to retrieve the day of the week. next I will summarize the specific operation methods for you, I hope this method will be helpful to all of you.
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: |
|
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: |
|
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: |
|
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: |
|
// 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: |
|
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 (); ?> |
...