How to increase time in php
How to increase time in php: first set the default time zone through "date_default_timezone_set"; then output tomorrow's time through "strtotime(' 1 day')"; finally modify the parameters to any number you want to increase.
php Add one day to a certain time? One hour? Time addition and subtraction
<?php date_default_timezone_set('PRC'); //默认时区 echo "今天:",date("Y-m-d",time()),"<br>"; echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>"; echo "昨天:",date("Y-m-d",strtotime("-1 day")),"<br>"; echo "明天:",date("Y-m-d",strtotime("+1 day")),"<br>"; echo "一周后:",date("Y-m-d",strtotime("+1 week")),"<br>"; echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>"; echo "下个星期四:",date("Y-m-d",strtotime("next Thursday")),"<br>"; echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>"; echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>"; echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>"; echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>"; ?>
//strtotime可以接受第二个参数,类型timestamp,为指定日期 echo date('Y-m-d', strtotime ("+1 day", strtotime('2011-11-01'))),"\n";
<?php echo "今天:",date('Y-m-d H:i:s'),"<br>";//输出当前时间 echo "明天:",date('Y-m-d H:i:s',strtotime('+1 day'));//输出明天时间 //这里+1 day 可以修改参数1为任何想需要的数 day也可以改成year(年),month(月),hour(小时),minute(分),second(秒) //如: date('Y-m-d H:i:s',strtotime("+1 day +1 hour +1 minute"); ?>
Note: This method was tried after 1970, which is the scope of application of timestamps.
<?php //下面这些代码是一些常用的日期处理函数了,可以两个时间的日期加减,两日期之差,日期转换时间截等。 echo date('Y-m-d',strtotime('+1 d',strtotime('2009-07-08')));//日期天数相加函数 echo date("Y-m-d",'1246982400'); echo '<br>'; echo date("Y-m-d",'1279123200'); die(); $d = "2009-07-08 10:19:00"; echo date("Y-m-d",strtotime("$d +1 day")); //日期天数相加函数 function dateToTime($d){//把日期转换成时间堆截 $year=((int)substr("$d",0,4));//取得年份 $month=((int)substr("$d",5,2));//取得月份 $day=((int)substr("$d",8,2));//取得几号 return mktime(0,0,0,$month,$day,$year); } $Date_1="2009-07-08"; echo $Date_1+1; $Date_2="2009-06-08"; $Date_List_a1=explode("-",$Date_1); $Date_List_a2=explode("-",$Date_2); $d1=mktime(0,0,0,$Date_List_a1[1],$Date_List_a1[2],$Date_List_a1[0]); $d2=mktime(0,0,0,$Date_List_a2[1],$Date_List_a2[2],$Date_List_a2[0]); $Days=round(($d1-$d2)/3600/24); echo "两日期之前相差有$Days 天"; ?>
Recommended: "PHP Tutorial"
The above is the detailed content of How to increase time in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.
