PHP uses datetime classes to make time and date to string conversions ____php

Source: Internet
Author: User
Tags datetime echo date time and date

PHP About time and date processing is not very normative, simple, is not know whether the input string can be correctly converted to the desired datetime type.

Object-oriented PHP should use a DateTime class to make string and datetime conversions

From string to TIME type
Datetime::createfromformat (' m/d/y h:i ', ' 03/01/2008 02:20 ');
$totalPrice = 0.0;
from DateTime to String
$datetime = new DateTime (' 2008-08-03 14:52:10 ');
echo $datetime->format (' JS, F Y '). "/n";
Get current time
GETDATE ()

Although this operation is a bit troublesome, but the various parts are their own precise control of the format, the mind is a bit of a better ah.

All of these are for PHP 5.3 only

The old version still needs this.

echo Date (' m/d/y h:i ', Strtotime (' 10/20/2009 15:21 '));

Note: Reading from the database using an array is a character type

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.