<?php
$date1 = new DateTime(null, new DateTimeZone(‘Asia/Calcutta’));
$timezone = $date1->getTimezone();
echo $timezone->getName();
?>
Output
Asia/Calcutta
<?php
$date1 = new DateTime(null, new DateTimeZone(‘Asia/Calcutta’));
$timezone = $date1->getTimezone();
echo $timezone->getName();
?>
Output
Asia/Calcutta
<?php
$date = new DateTime();
echo $date->format(‘U = Y-m-d H:i:s’) . “<br />”;
$date->setTimestamp(1181503727);
echo $date->format(‘U = Y-m-d H:i:s’) ;
?>
Output
1335329861 = 2012-04-25 10:27:41
1181503727 = 2007-06-11 00:58:47
<?php
$date1 = date_create();
echo date_format($date1, ‘U = Y-m-d H:i:s’).”<br />”;
date_timestamp_set($date1, 1171502325);
echo date_format($date1, ‘U = Y-m-d H:i:s’);
?>
Output
1335329740 = 2012-04-25 10:25:40
1171502325 = 2007-02-15 06:48:45
<?php
$date1 = new DateTime();
echo $date1->getTimestamp();
?>
Output
1335328144
Output
2001-05-17 12:52:00
<?php
$date = date_create(‘2001-05-17’);
date_time_set($date, 17, 54);
echo date_format($date, ‘Y-m-d H:i:s’) . “n”;
?>
Output
2001-05-17 17:54:00
<?php
$date = new DateTime(‘2012-05-17’);
$date->sub(new DateInterval(‘P11D’));
echo $date->format(‘Y-m-d’) . “n”;
?>
Output
2012-05-06
<?php
$time = new DateTime(‘2008-05-17’, new DateTimeZone(‘America/New_York’));
echo $time->getOffset() . “n”;
?>
Output
-14400
<?php date_default_timezone_set('America/Los_Angeles'); ?>