Home  >  Article  >  Backend Development  >  Detailed explanation and difference between php time time and date date

Detailed explanation and difference between php time time and date date

高洛峰
高洛峰Original
2016-12-26 13:20:451515browse

The difference between time and date in php

1. time() function

The time() function in PHP, using echo output, it is a A very long integer that contains date and time and is a calculated value. If you want to get a date format like Y-m-d H:i:s, you can use the date method:

date('Y-m-d H:i:s', time());

echo output it to get: 2016-1-5 10:20:11

2. Date format and string

We can construct a date format string ourselves, such as: 2015-1-1 10:20:11. You can use the strtotime() function to convert this string into a time format value. For example:

$time1 = strtotime('2016-1-5 10:20:11');

This value is echo output and a long integer is obtained.

So, it can be understood like this:

The date is saved as a long integer number in php. It can be converted into a date (estimately called date) type through the date function, and the date type can directly output a string.

The date string can be converted to time format (that is, a long integer) using the strtotime() function.

Date format can be converted to long integer through int forced type conversion.

Thank you for reading, I hope it can help you, thank you for your support of this site!

For more detailed explanations and differences between PHP time and date, please pay attention to the PHP Chinese website for related articles!


Statement:
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