php timestamp conversion
php timestamp conversion method: 1. Use the "date("Y-m-d H:i",$unixtime)" method to convert the timestamp into date; 2. Use the "strtotime("today")" method to convert the timestamp into date Convert date to timestamp.
Recommended manual: php complete self-study manual
In php we have to take time Stamp conversion to date can be implemented directly using the date function. If you want to convert date into a timestamp, you can use the strtotime() function. Let me give you an example below.
Online tool recommendation: Unix timestamp conversion tool
1.Time conversion function in php
strtotime (date()) date("Y-m-d H:i",$unixtime)
2.Get today's zero time timestamp in php. To get the zero time unix timestamp, you can use
$todaytime=strtotime(“today”)
and then use
date("Y-m-d H:i",$todaytime)
to convert to date.
Recommended related articles:
1.php gets the number of the current timestamp
2.PHP gets the current timestamp function Detailed explanation
Related video recommendations:
1.Dugu Jiujian(4)_PHP video tutorial
Convert timestamp to date
Time stamp conversion function:
date("Y-m-d H:i:s",time()),"Y-m-d H:i: s" is the converted date format, time() is the timestamp to obtain the current time. If it is date("Y-m-d H:i:s", time()), the hours, minutes and seconds will be displayed together; if it is
date("Y-m-d ", time( )), only the year, month and day are displayed. For example:
date("Y-m-d H:i:s",time())
after conversion is:
2010-07-18 18:42:48
date("Y-m-d",time())
After conversion:
2010-07-18 Date conversion It is a timestamp.
class SaonekController extends Controller { public function index Action (){ /*
It goes without saying that the timestamp is converted into a date
But if the date is to be converted into a timestamp, it must be used
strtotime() */ $time = time();//
Timestamp
$nowtime = date('Y-m-d H:i:s',$time);//
Generate formatted date
$oldtime = '2010-11-10 22:19:21'; $catime = strtotime($oldtime);//
Convert date to timestamp
$nowtimes = date('Y-m-d H:i:s',$catime);//
Time stamp is converted back to date
echo $nowtimes; } } ?>
Convert timestamp to date in 3.php , and display different content according to time, such as just now, minutes ago, hours ago, today, yesterday, etc.
/* 时间转换函数 */ function transTime($ustime) { $ytime = date("Y-m-d H:i",$ustime); $rtime = date("n月j日 H:i",$ustime); $htime = date("H:i",$ustime); $time = time() - $ustime; $todaytime = strtotime("today"); $time1 = time() - $todaytime; if($time < 60){ $str = '刚刚'; }else if($time < 60 * 60){ $min = floor($time/60); $str = $min.'分钟前'; }else if($time < $time1){ $str = '今天'.$htime; }else{ $str = $rtime; } return $str; }
Other references
Use date to set the timestamp Convert the specified timestamp to system time
(1) Print the timestamp at this time tomorrow
strtotime(”+1 day“)
Current time:
echo date(”Y-m-d H:i:s”,time())
Result:
2009-01-22 09:40:25
Specified time:
echo date(”Y-m-d H:i:s”,strtotime(”+1 day”))
Result:
2009-01-23 09:40:25
(2) Print the timestamp at this time yesterday
PHP 时间戳 strtotime(”-1 day“) 当前时间: echo date( ”Y-m-d H:i:s”,time()) 结果: 2009-01-22 09:40:25 指定时间: echo date(”Y-m-d H:i:s”,strtotime(”-1 day”)) 结果: 2009-01-21 09:40:25
(3) Print the timestamp at this time next week
strtotime(”+1 week“) 当前时间: echo date(”Y-m-d H:i:s”,time()) 结果: 2009-01-22 09:40:25 指定时间: echo date(”Y-m-d H:i:s”,strtotime(”+1 week”)) 结果: 2009-01-29 09:40:25
(4) Print the timestamp of last week at this time
strtotime(”-1 week“) 当前时间: echo date(”Y-m-d H:i:s”,time()) 结果: 2009-01-22 09:40:25 指定时间: echo date(”Y-m-d H:i:s”,strtotime(”-1 week”)) 结果: 2009-01-15 09:40:25
(5) Print the PHP timestamp of the specified day of next week
strtotime(”next Thursday“) 当前时间: echo date(”Y-m-d H:i:s”,time()) 结果: 2009-01-22 09:40:25 指定时间: echo date(”Y-m-d H:i:s”,strtotime(”next Thursday”)) 结果: 2009-01-29 00:00:00
(6) Print the specified day of last week Timestamp
strtotime(”last Thursday“) 当前时间: echo date(”Y-m-d H:i:s”,time()) 结果: 2009-01-22 09:40:25 指定时间: echo date(”Y-m-d H:i:s”,strtotime(”last Thursday”)) 结果: 2009-01-15 00:00:00
For more PHP related technical articles, please visit the PHP Tutorial column to learn!
The above is the detailed content of php timestamp conversion. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.
