i have a time zone in 2010-05-04T05:27:00.000Z format which indicates the GMT time and i want to add GMT 10+ in to it using php.
i can do that thing using following code but how would i directly add 2010-05-04T05:27:00.000Z and GMT 10+ so that i can get a valid date and time.
$offset=10*60*60;
$dateFormat="d-m-Y H:i::m:s";
echo $timeNdate=gmdate($dateFormat, time()+$offset);
Maybe I'm missing the point but are you not really looking for DateTime::setTimezone
?
$timezone = new DateTimeZone('Etc/GMT-10'); // GMT+10:00
$datetime = new DateTime('2010-05-04T05:27:00.000Z');
$datetime->setTimezone($timezone);
echo $datetime->format('r');
// Tue, 04 May 2010 15:27:00 +1000
Use DateTime
class http://php.net/manual/en/book.datetime.php exacly DateTime::Add()
http://www.php.net/manual/en/datetime.add.php
You have some example here:
<?php
$date = new DateTime('2000-01-01');
$date->add(new DateInterval('PT10H30S'));
echo $date->format('Y-m-d H:i:s') . "\n";
$date = new DateTime('2000-01-01');
$date->add(new DateInterval('P7Y5M4DT4H3M2S'));
echo $date->format('Y-m-d H:i:s') . "\n";
?>
And another:
<?php
$date = new DateTime('2000-12-31');
$interval = new DateInterval('P1M');
$date->add($interval);
echo $date->format('Y-m-d') . "\n";
$date->add($interval);
echo $date->format('Y-m-d') . "\n";
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.