Initialize the object $date = new DateTime(); We can get timezone using following method $date->getTimezone(); We can set timezone using following method $date->setTimezone(new DateTimeZone('Asia/Calcutta')); Format of date $date->format('d-m-Y H:i:s'); Timestamp $date->getTimestamp(); $date->setTimestamp(1544972289); $date->format('d-m-Y H:i:s'); Interval //get date after 10 days and 2 hours $date->add(new DateInterval('P10DT2H')); //get date before 10 days and 2 hours $date->sub(new DateInterval('P10DT2H')); // after one month $date->modify('+1 month'); Difference between dates $birthdate = new DateTime("2000-01-01"); $diff=$birthdate->diff($date); echo $diff->y." years, ".$diff->m." months, ".$diff->d." days";
Php Web Development Blog