Use the DateTime class in PHP to convert time and date to string

Source: Internet
Author: User
PHP's processing of time and date is not very standard. It is simple, that is, it does not know whether the input string can be correctly converted to the required DateTime type. Object-oriented PHP should use the DateTime class for string and dateTime conversion from string to time type DateTime: createFromFormat (mdYH: I, 0301200802: 2

PHP's processing of time and date is not very standard. It is simple, that is, it does not know whether the input string can be correctly converted to the required DateTime type. Object-oriented PHP should use the DateTime class for string and dateTime conversion from string to time type DateTime: createFromFormat (m/d/y h: I ', '2017/03/01

PHP's processing of time and date is not very standard. It is simple, that is, it does not know whether the input string can be correctly converted to the required DateTime type.

Object-oriented PHP should use the DateTime class for string and dateTime conversion.

From string to time type
DateTime: createFromFormat ('m/d/y h: I ', '2017/0:20 ');
$ TotalPrice = 0.0;
From DateTime to string
$ Datetime = new DateTime ('2017-08-03 14:52:10 ');
Echo $ datetime-> format ('js, fy'). "/n ";
Get current time
Getdate ()

Although this operation is a little troublesome, all parts are self-controlled formats.

All of the above are available for PHP 5.3

The old version still uses this

Echo date ('m/d/y h: I ', strtotime ('2014/1/24/60 '));

Note: An array is read from the database as a struct type.

Related Article

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.