Hướng dẫn php time() function
Tác giả: Dương Nguyễn Phú Cường Show Ngày đăng: Hồi xưa đó What is PHP Date Function?PHP date function is an in-built function that simplify working with date data types. The PHP date function is used to format a date or time into a human readable format. It can be used to display the date of article was published. record the last updated a data in a database. PHP Date Syntax & ExamplePHP Date the following basic syntax HERE,
Let’s look at a basic example that displays the current year. Output: 2018 What is a TimeStamp?A timestamp is a numeric value in seconds between the current time and value as at 1st January, 1970 00:00:00 Greenwich Mean Time (GMT). The value returned by the time function depends on the default time zone. The default time zone is set in the php.ini file. It can also be set programmatically using date_default_timezone_set function. The code below displays the current time stamp Assuming you saved the file timestamp.php in phptuts folder, browse to the URL http://localhost/phptuts/timestamp.php Note: the value of the timestamp is not a constant. It changes every second.Getting a list of available time zone identifiersBefore we look at how to set the default time zone programmatically, let’s look at how to get a list of supported time zones. $list){ echo $list . " HERE,
Assuming you saved the file list_time_zones.php in phptuts folder, browse to the URL http://localhost/phptuts/list_time_zones.php PHP set Timezone ProgrammaticallyThe date_default_timezone_set function allows you to set the default time zone from a PHP script. The set time zone will then be used by all date php function scripts. It has the following syntax. HERE,
The script below displays the time according to the default time zone set in php.ini. It then changes the default time zone to Asia/Calcutta and displays the time again. Assuming you have saved the file set_time_zone.php in the phptuts folder, browse to the URL http://localhost/phptuts/set_time_zone.php PHP Mktime FunctionThe mktime function returns the timestamp in a Unix format. It has the following syntax. HERE,
Let’s now look at an example that creates a timestamp for the date 13/10/2025 using the mktime function. HERE,
Output: 1760328000 PHP Date function referenceThe table below shows the common parameters used when working with the date php function. PHP Time parameters
Day parameters
Month Parameters
Year Parameters
Summary
|