In php, if we want to obtain the day of the week, we can directly use the date function for operations. Next I will summarize the specific operation methods for you. I hope this method will help 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: |
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 (); ?> |