PHP date and time, PHP Date and Time

Source: Internet
Author: User

PHP date and time, PHP Date and Time

1. date

string date ( string $format [, int $timestamp ] )

 

Echo date ('y'). '<br/>'; // 2016
Echo date ('y'). '<br/>'; // 16

Echo '------ <br/> ';

Echo date ('M'). '<br/>'; // 03
Echo date ('M'). '<br/>'; // Mar. uppercase M indicates the three abbreviated characters of the month.
Echo date ('n'). '<br/>'; // 3,
Echo date ('F'). '<br/>'; // March, which indicates all the English letters of the month.

Echo '------ <br/> ';

Echo date ('D'). '<br/>'; // 09
Echo date ('J'). '<br/>'; // 9
Echo date ('s'). '<br/>'; // th, indicating the date suffix.

Echo '------ <br/> ';

Echo date ('G'). '<br/>'; // 4, in 12-hour format, without 0
Echo date ('G'). '<br/>'; // 16, in 24-hour format, with leading 0
Echo date ('H'). '<br/>'; // 16,24 hour system, with no 0 in front
Echo date ('H'). '<br/>'; // 01, in 12-hour format, with leading 0

Echo '------ <br/> ';

Echo date ('I'). '<br/>'; // 42, minutes

Echo '------ <br/> ';

Echo date ('s'). '<br/>'; // 26, seconds
Echo date ('s'). '<br/>'; // th, indicating the date suffix.

Echo '------ <br/> ';

Echo date ('A'). '<br/>'; // pm, lowercase am (morning) pm (afternoon)
Echo date ('A'). '<br/>'; // PM, uppercase

Echo '------ <br/> ';

Echo date ('l'). '<br/>'; // Thursday, which is the day of the week in full (Tuesday)
Echo date ('l'). '<br/>'; // 1. 1 is returned for a leap year. Otherwise, 0 is returned.
Echo date ('D'). '<br/>'; // Thu, which is the abbreviation of the three characters of the day of the week (Tue)


2. mktime ()

Mktime generates a timestamp for the specified time. prototype:

int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [,int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1]]]]]]] )

$ Tomorrow = mktime (0, 0, 0, date ("m"), date ("d") + 1, date ("Y "));
Echo "tomorrow is". date ("Y/m/d", $ tomorrow );

3. strtotime ()

$ D = strtotime ("pm else l 15 2015 ");
Echo "creation date is". date ("Y-m-d h: I: sa", $ d );

$ D = strtotime ("tomorrow ");
Echo date ("Y-m-d h: I: sa", $ d). "<br> ";

$ D = strtotime ("next Saturday ");
Echo date ("Y-m-d h: I: sa", $ d). "<br> ";

$ D = strtotime ("+ 3 Months ");
Echo date ("Y-m-d h: I: sa", $ d). "<br> ";

 

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.