在php中设置应用程序时区加一周

I want to set my Php application time to + 1 week .

I have set time zone below code

date_default_timezone_set('Asia/Kolkata'); 

so application time changed to Asia/Kolkata, but i want change application time to + 1 week

For example : when i print date using php code in application

date("Y/m/d")  

i need get output Apr-12-2017.

is it feasible to change default timezone + 1 week ,

please help ,Thanks

A week is 7*24*60*60 = 604800 seconds. So, while leaving everything on the server as it should, one week from now is:

date('Y/m/d',time()+604800)

But I prefer the one Deep Kakkar also mentions:

date('Y/m/d',strtotime("+1 week"))

It just looks nicer.

You need to do this manually. You can use the DateTime class to do calendar calculations. For example, to add one week, you could use code like this:

$date = new DateTime('05-04-2017');
$date->modify('+1 week');

OR, you can choose strtotime.

echo date('d-m-Y', strtotime("+1 week")); //1 week in the future

Now , either you can initialise the date variable value as globally in your project and call at required place or create it on each and every position as per required.

try below one:

<?php
echo date("Y/m/d", strtotime("+1 week"));

You can use the DateTime class, and extend it to a class of your own, that always adds 1 week to every DateTime object.

So if you do new MyDateTime("now"); you would get the date one week from now. If you did new MyDateTime("+1 week");, you get two weeks (one from the argument to the constructor, one from the modification inside the class constructor).

class MyDateTime extends DateTime {
    function __construct(string $time = "now", DateTimeZone $timezone = null) {
        parent::__construct($time, new DateTimeZone("UTC"));
        $this->modify("+1 week");
    }
}

$date = new MyDateTime();
echo $date->format("F jS, Y")."
"; // +1 week from now

$one_week = new MyDateTime("+1 week");
echo $one_week ->format("F jS, Y"); // +2 weeks from now

Live demo