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