" ; } $mydate = getdate ( date ( "U" )); //bạn tham khảo hàm date() ở bên dưới print "Today: " ; echo "$mydate[weekday], $mydate[month] $mydate[mday], $mydate[year]" ; ?>
Save the above program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php will result:
The date () function in PHP returns a formatted string representing a date. You can practice various controls through the format that the date () function returns with a string parameter that you want to pass to it.
date (format, timestamp)
If you do not use (optionally) a Time stamp in the date () function, the current date and time will be used. Any other data you include in the format string passed to date () will be included in the return value.
The table below lists some code that a format string can contain:
Format Description Example 'am' or 'pm' in lowercase pm A 'AM' or 'PM' in upper case PM d Date of the month, number starting from 01 20 D Weekdays (3 letters) Thu F January h Hour (12h format, from 01) 12 H Hour (24h format, from 01) 22 g Hours (12h format, from 1) 12 G Hours (24h format, format 1) 22 i Minutes (0 - 59) 23 j Day of the month (form 1) 20 l (Lower 'L') Day of the week Thursday L Leap year ('1' for yes, '0' for full) 1 m Month of the year (number, form 01) 1 M Month of the year (3 letters) Jan r Date in RFC format 2822 Thu, 21 Dec 2000 16:01:07 +0200 n Month of the year (number, form 1) 2 s Seconds in hour 20 U Time stamp 948372444 y Year (2 digits) 06 Y Year (4 digits) 2006 z Date of the year (0 - 365) 206 Z Offset equals the seconds value from GMT +5For example
You try the following example of the date () function in PHP:
php // in ngày trong tuần echo date ( "l" ) . "
" ; // in ngày trong tuần, ngày trong tháng, tháng, năm, thời gian, AM hoặc PM echo date ( "l jS of F Y h:i:s A" ) . "
" ; // hiển thị October 3, 1975 là vào Friday echo "Oct 3,1975 was on a " . date ( "l" , mktime ( 0 , 0 , 0 , 10 , 3 , 1975 )) . "
" ; // sử dụng một hằng số trong tham số format echo date ( DATE_RFC822 ) . "
" ; // hiển thị date time dưới dạng giống như: 1975-10-03T00:00:00+00:00 echo date ( DATE_ATOM , mktime ( 0 , 0 , 0 , 10 , 3 , 1975 )); ?>
Save the above program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php will result:
Hope you understand how the date format and time are according to your requirements. A complete list of all date and time operation functions is provided in the chapter Function handling Date & Time in PHP
Follow tutorialspoint
Previous article: PHP for PERL Programmers
Next lesson: What is JavaScript