How PHP Gets the time

Source: Internet
Author: User
This article introduces how PHP gets the time

$year = Date ("Y");//year 2018 if "Y" is lowercase, the output is shorthand for the year, such as: 2018, the output is: 18$month =date ("M");//month 2 if "M" uppercase, the output is the English month, lowercase is the number of the date of the =date ("D"); $week =date ("L");//day of the Week $last_month_days = Cal_days_in_month (Cal_gregorian, $month-1, $year);//number of days on January $month = Date (" M ") $now _month_days = Cal_days_in_month (Cal_gregorian, $month, $year);//number of days of the current month; $month = Date (" M ") cal_days_in_month public : Returns the number of days of a month in a calendar year $next_month_days=cal_days_in_month (Cal_gregorian, $month +1, $year); if ($year%4==0 && $now _ month_days==28) {$now _month_days = $now _month_days+1;//judge that the current month is not a leap year, that is, February plus one day, that is, 29 days} $week _date = Date ("W", Strtotime (" 2018-2-5 ")); The string specifies the date to get the day of the Week $week_date = Date ("W", Strtotime (Date ("y-m-d)"); variable specifies the day of the Week $week_date = Date ("W", Strtotime ($year. " -". $month." -"." 1 "));//splicing string specifies the monthly period of 1th, the day of   the week Cal_days_in_month public: Returns the number of days of a month in a calendar

Parameter description:

Cal_days_in_month (PAR1,PAR2, $par 3);

$par 1: A calendar for calculation, PHP calendar constant

PAR2: Parameter Par1 Select a month in the calendar

$par 3: Select a year in the calendar

return value:

$par 1 days of the month of the selected calendar

PHP Calendar constants: The calendar extension contains functions that simplify conversion between different calendar formats.

In order for these functions to work, you must compile PHP through –enable-calendar. window, the support for calendar extensions has been integrated

The constants in the case are Cal_gregorian, which are predefined constants of PHP, like constants such as Php_os

Gregorian means: Gregorian calendar; Solar Calendar

This article introduces the method of PHP acquisition time, more relevant content please follow the PHP Chinese web.

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.