Hướng dẫn PHP

TRANG CHỦ PHP Giới thiệu PHP Cài đặt PHP Cú pháp PHP Nhận xét PHP Các biến PHP PHP Echo / Print Các kiểu dữ liệu PHP Chuỗi PHP Số PHP Toán PHP Hằng số PHP Toán tử PHP PHP If ... Else ... Elseif Chuyển đổi PHP Vòng lặp PHP Các hàm PHP Mảng PHP PHP Superglobals PHP RegEx

Biểu mẫu PHP

Xử lý biểu mẫu PHP Xác thực biểu mẫu PHP Yêu cầu biểu mẫu PHP URL biểu mẫu PHP / E-mail Hoàn thành biểu mẫu PHP

PHP nâng cao

Ngày và giờ trong PHP Bao gồm PHP Xử lý tệp PHP Mở / Đọc tệp PHP Tạo / ghi tệp PHP Tải lên tệp PHP Cookie PHP Phiên PHP Bộ lọc PHP Bộ lọc PHP nâng cao Các chức năng gọi lại trong PHP PHP JSON Ngoại lệ PHP

PHP OOP

PHP OOP là gì Các lớp / đối tượng PHP Trình tạo PHP PHP Destructor Công cụ sửa đổi quyền truy cập PHP Kế thừa PHP Hằng số PHP Các lớp trừu tượng trong PHP Giao diện PHP Đặc điểm PHP Phương thức tĩnh trong PHP Thuộc tính tĩnh của PHP Không gian tên PHP Lặp lại PHP

Cơ sở dữ liệu MySQL

Cơ sở dữ liệu MySQL MySQL Connect MySQL Tạo cơ sở dữ liệu MySQL Tạo bảng MySQL Chèn dữ liệu MySQL Nhận ID cuối cùng MySQL Chèn Nhiều MySQL được chuẩn bị Dữ liệu chọn MySQL MySQL ở đâu MySQL Đặt hàng bởi MySQL Xóa dữ liệu Dữ liệu cập nhật MySQL Dữ liệu giới hạn MySQL

PHP XML

Trình phân tích cú pháp XML PHP Trình phân tích cú pháp PHP SimpleXML PHP SimpleXML - Nhận PHP XML Expat DOM XML PHP

PHP - AJAX

Giới thiệu về AJAX AJAX PHP Cơ sở dữ liệu AJAX AJAX XML Tìm kiếm trực tiếp AJAX Cuộc thăm dò ý kiến ​​của AJAX

Ví dụ về PHP

Ví dụ về PHP Trình biên dịch PHP PHP Quiz Bài tập PHP Chứng chỉ PHP

Tham chiếu PHP

Tổng quan về PHP Mảng PHP Lịch PHP Ngày PHP Thư mục PHP Lỗi PHP Ngoại lệ PHP Hệ thống tập tin PHP Bộ lọc PHP FTP PHP PHP JSON Từ khóa PHP PHP Libxml Thư PHP Toán PHP PHP Misc PHP MySQLi Mạng PHP Kiểm soát đầu ra PHP PHP RegEx PHP SimpleXML Luồng PHP Chuỗi PHP Xử lý biến PHP Trình phân tích cú pháp XML PHP PHP Zip Múi giờ PHP

Các hàm Ngày / Giờ trong PHP


Giới thiệu Ngày / Giờ trong PHP

Các hàm ngày / giờ cho phép bạn lấy ngày và giờ từ máy chủ nơi tập lệnh PHP của bạn chạy. Sau đó, bạn có thể sử dụng các hàm ngày / giờ để định dạng ngày và giờ theo một số cách.

Lưu ý: Các chức năng này phụ thuộc vào cài đặt ngôn ngữ của máy chủ của bạn. Hãy nhớ cân nhắc thời gian tiết kiệm ánh sáng ban ngày và năm nhuận khi làm việc với các chức năng này.


Cài đặt

Các hàm ngày / giờ trong PHP là một phần của lõi PHP. Không cần cài đặt để sử dụng các chức năng này.


Cấu hình thời gian chạy

Hoạt động của các chức năng này bị ảnh hưởng bởi cài đặt trong php.ini:

Name Description Default PHP Version
date.timezone The default timezone (used by all date/time functions) "" PHP 5.1
date.default_latitude The default latitude (used by date_sunrise() and date_sunset())  "31.7667" PHP 5.0
date.default_longitude The default longitude (used by date_sunrise() and date_sunset()) "35.2333" PHP 5.0
date.sunrise_zenith The default sunrise zenith (used by date_sunrise() and date_sunset()) "90.83" PHP 5.0
date.sunset_zenith The default sunset zenith (used by date_sunrise() and date_sunset()) "90.83" PHP 5.0


Các hàm Ngày / Giờ trong PHP

Function Description
checkdate() Validates a Gregorian date
date_add() Adds days, months, years, hours, minutes, and seconds to a date
date_create_from_format() Returns a new DateTime object formatted according to a specified format
date_create() Returns a new DateTime object
date_date_set() Sets a new date
date_default_timezone_get() Returns the default timezone used by all date/time functions
date_default_timezone_set() Sets the default timezone used by all date/time functions
date_diff() Returns the difference between two dates
date_format() Returns a date formatted according to a specified format
date_get_last_errors() Returns the warnings/errors found in a date string
date_interval_create_from_date_string() Sets up a DateInterval from the relative parts of the string
date_interval_format() Formats the interval
date_isodate_set() Sets the ISO date
date_modify() Modifies the timestamp
date_offset_get() Returns the timezone offset
date_parse_from_format() Returns an associative array with detailed info about a specified date, according to a specified format
date_parse() Returns an associative array with detailed info about a specified date
date_sub() Subtracts days, months, years, hours, minutes, and seconds from a date
date_sun_info() Returns an array containing info about sunset/sunrise and twilight begin/end, for a specified day and location
date_sunrise() Returns the sunrise time for a specified day and location
date_sunset() Returns the sunset time for a specified day and location
date_time_set() Sets the time
date_timestamp_get() Returns the Unix timestamp
date_timestamp_set() Sets the date and time based on a Unix timestamp
date_timezone_get() Returns the time zone of the given DateTime object
date_timezone_set() Sets the time zone for the DateTime object
date() Formats a local date and time
getdate() Returns date/time information of a timestamp or the current local date/time
gettimeofday() Returns the current time
gmdate() Formats a GMT/UTC date and time
gmmktime() Returns the Unix timestamp for a GMT date
gmstrftime() Formats a GMT/UTC date and time according to locale settings
idate() Formats a local time/date as integer
localtime() Returns the local time
microtime() Returns the current Unix timestamp with microseconds
mktime() Returns the Unix timestamp for a date
strftime() Formats a local time and/or date according to locale settings
strptime() Parses a time/date generated with strftime()
strtotime() Parses an English textual datetime into a Unix timestamp
time() Returns the current time as a Unix timestamp
timezone_abbreviations_list() Returns an associative array containing dst, offset, and the timezone name
timezone_identifiers_list() Returns an indexed array with all timezone identifiers
timezone_location_get() Returns location information for a specified timezone
timezone_name_from_ abbr() Returns the timezone name from abbreviation
timezone_name_get() Returns the name of the timezone
timezone_offset_get() Returns the timezone offset from GMT
timezone_open() Creates new DateTimeZone object
timezone_transitions_get() Returns all transitions for the timezone
timezone_version_get() Returns the version of the timezonedb

Hằng số ngày / giờ được xác định trước trong PHP

Constant Description
DATE_ATOM Atom (example: 2019-01-18T14:13:03+00:00)
DATE_COOKIE HTTP Cookies (example: Fri, 18 Jan 2019 14:13:03 UTC)
DATE_ISO8601 ISO-8601 (example: 2019-01-18T14:13:03+0000)
DATE_RFC822 RFC 822 (example: Fri, 18 Jan 2019 14:13:03 +0000)
DATE_RFC850 RFC 850 (example: Friday, 18-Jan-19 14:13:03 UTC)
DATE_RFC1036 RFC 1036 (example: Friday, 18-Jan-19 14:13:03 +0000)
DATE_RFC1123 RFC 1123 (example: Fri, 18 Jan 2019 14:13:03 +0000)
DATE_RFC2822 RFC 2822 (example: Fri, 18 Jan 2019 14:13:03 +0000)
DATE_RFC3339 Same as DATE_ATOM (since PHP 5.1.3)
DATE_RFC3339_EXTENDED RFC3339 Extended format (since PHP 7.0.0) (example: 2019-01-18T16:34:01.000+00:00)
DATE_RSS RSS (Fri, 18 Jan 2019 14:13:03 +0000)
DATE_W3C World Wide Web Consortium (example: 2019-01-18T14:13:03+00:00)
SUNFUNCS_RET_TIMESTAMP Timestamp (since PHP 5.1.2)
SUNFUNCS_RET_STRING Hours:minutes (example: 09:41) (since PHP 5.1.2)
SUNFUNCS_RET_DOUBLE Hours as a floating point number (example: 9.75) (since PHP 5.1.2)