How to get the current time in php

(*-*)浩
Release: 2023-02-24 14:02:01
Original
11466 people have browsed it

The Date/Time function allows you to get the date and time from the server the PHP script is running on. You can use the Date/Time functions to format dates and times in different ways.

How to get the current time in php

#Note: These functions depend on the local settings of the server. Remember to take daylight saving time and leap years into account when using these functions.

PHP Date/Time functions are an integral part of PHP core. No installation is required to use these functions. (Recommended learning: PHP programming from entry to proficiency)

Get the current date and time through the date() function in PHP

date(string format,int timestamp)
Copy after login

The date() function will return a string generated by the timestamp parameter according to the specified format. The timestamp parameter is optional. If omitted, the current time will be used. The format parameter can be the date and time output in the format specified by the developer.

<?php
date_default_timezone_set("Asia/Hong_Kong");
echo "mktime函数返回的时间戳:".mktime()."<p>";
echo "当前的日期为:".date("Y-m-d",mktime())."<p>";
echo "当前的时间为:".date("H:i:s",mktime());
?>
Copy after login

Use function date() to realize

<?php echo $showtime=date("Y-m-d H:i:s");?>
Copy after login

Display format: year-month-day hour: minute: second

The above is the detailed content of How to get the current time in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!