Home > Backend Development > PHP Tutorial > How to get time in php

How to get time in php

jacklove
Release: 2023-03-27 13:36:02
Original
2240 people have browsed it

This article introduces the method of obtaining time in php

$year = date("Y");// 年 2018 如果“Y” 小写,输出是年份简写,如:2018年,输出是:18
$month =date("m");// 月 2 如果“M” 大写,输出是英文月份,小写是数字
$day =date("d");// 日$week =date("l");// 星期几
$last_month_days = cal_days_in_month(CAL_GREGORIAN, $month-1,$year);// 上一月的天数 $month = date("m")
$now_month_days = cal_days_in_month(CAL_GREGORIAN, $month,$year);// 当年月的天数; $month = date("m")
cal_days_in_month 的公用:返回某个历法中某年中某月的天数
$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;// 判断当前月是不闰年,是的话 2月加一天,即29天
}
$week_date = date("w",strtotime("2018-2-5")); // 字符串指定日期获得星期几
$week_date = date("w",strtotime(date("Y-m-d))); // 变量指定日期获得星期几
$week_date = date("w",strtotime($year."-".$month."-"."1"));//拼接字符串指定每月 1 号期,获得星期几   
cal_days_in_month 的公用:返回某个历法中某年中某月的天数
Copy after login

Parameter introduction:

cal_days_in_month(par1,par2,$par3);

$par1: used for calculation A certain calendar, PHP Calendar constant

par2: Parameter par1 selects a certain month in the calendar

$par3: Selects a certain year in the calendar

Return value:

$par1 The number of days in a certain year and 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 with –enable-calendar. Under window, support for calendar extension has been integrated.

The constant CAL_GREGORIAN in the case is a PHP predefined constant, just like constants such as PHP_OS.

gregorian means: Gregorian calendar; Gregorian calendar

This article introduces the method of obtaining time in php. For more related content, please pay attention to php Chinese website.

Related recommendations:

php object-oriented selection sorting example explanation

PHP skills: cleverly use json_encode() to js Array assignment

Features and syntax instructions of PHP and XML technology

The above is the detailed content of How to get time in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template