The use of PHP time and date dates with detailed and differentiated _php skills

Source: Internet
Author: User
Tags time and date

The usage difference between PHP time and date dates

1. Time () function

The time () function in PHP, using the echo output, is a very long integer that contains the date and times and is a computed value. If you want to get a date format such as y-m-d h:i:s, you can use the date method:

Date (' y-m-d h:i:s ', Time ());

echo output It can be obtained: 2016-1-5 10:20:11

2, date format and string

We can build a string of date format, such as: 2015-1-1 10:20:11. You can use the Strtotime () function to convert this string to a value in time format. Such as:

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

This value, echo output, gets a long integer.

So, you can understand this:

  1. The date is saved in PHP as a long shaping number. It can be converted to a date (estimate and date) type through the date function, and the date type can directly output the string.
  2. Date strings can be converted to time format (that is, long integers) using the Strtotime () function.
  3. Date format, you can force type conversions through int, and convert growth integers.

Thank you for reading, I hope to help you, thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.